November 14, 2005 at 5:43 am
hi
please help me how can i check a perticular column value weather it is number, char or alpha numeric in select statement
thanks & regards
deshbandhu
November 14, 2005 at 6:08 am
If you want to check for a specific position, then you can use "substring" otherwise you could try something like this - comment out the 'Hullo' first and then '12345' to see the 2 different print messages:
declare @VarChar VarChar(5) set @VarChar = 'Hullo' --set @VarChar = '12345' if isnumeric(@VarChar) = 1 print 'it is a number' else print 'it is not a number'
**ASCII stupid question, get a stupid ANSI !!!**
November 14, 2005 at 6:19 am
..or use LIKE / NOT LIKE with wildcards if ISNUMERIC() doesn't cut it.
Using wildcards will also provide some control that ISNUMERIC() doesn't give you, should it be needed.
BOL has a nice section on 'LIKE' keyword showing some techniques with wildcards and patternmatching.
/Kenneth
November 15, 2005 at 9:55 pm
As Kenneth suggested, ISNUMERIC may not cut it. It allows for seemingly non-numeric characters such as "d", "e", and "." so that it will support scientific and exponential notation. Continuing Sushila's fine example...
DECLARE @TestString VARCHAR(100)
SET @TestString = '12345' --<< Change this to test...
SELECT CASE
WHEN @TestString NOT LIKE '%[^0-9]%' THEN 'All Numeric'
WHEN @TestString NOT LIKE '%[0-9]%' THEN 'All Alpha'
ELSE 'Mixed'
END
Again, as Kenneth suggested, it depends on what you want... you could allow the decimal point and other characters depending on what your definition of a trully numeric value might be. Most people mean "All Digits" when they say "Is Numeric".
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply