-
Sep 15th, 2004, 03:22 PM
#1
Numeric From nvarchar (SQL 2k) [Resolved]
I need to create this query that will grab the Duration field, but
the problem is that the data is of nvarchar type and the actual
data is like "**7NTS" or "***7NTS" or "14NTS" or "**21", etc. I
want to use a loop to check each char position, but dont know if
possible. Or strip out non-numeric data somehow. This is what I
have so far.
Code:
SELECT
CASE Duration
WHEN ISNUMERIC(Duration) = 1 THEN
Duration = Duration --?
WHEN ISNUMERIC(Duration) = 0 THEN
WHILE ISNUMERIC(SUBSTRING(Duration,1,1)) = 1 --Need to check each char ?
BEGIN
--SOMETHING HERE
IF SOMETHING THEN
BREAK
ELSE
CONTINUE
END
END
FROM Table1
Last edited by RobDog888; Sep 15th, 2004 at 04:44 PM.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Sep 15th, 2004, 04:09 PM
#2
Code:
Declare @STR varchar(10)
Declare @NUM varchar(10)
Declare @VAL int
Set @STR='**21NTS'
Set @NUM=''
While @STR<>''
Begin
If IsNumeric(Left(@STR,1))=1 Set @Num=@Num+Left(@Str,1)
Set @Str=Right(@Str,Len(@Str)-1)
End
Set @Val=Cast(@Num as int)
Print @Val
Put that into a USER DEFINED function and you can use it in-line in a SELECT statement.
-
Sep 15th, 2004, 04:44 PM
#3
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|