|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 11:21 AM
Points: 2,163,
Visits: 2,148
|
|
| Nice questions thanks! Yet more reasons to not use ISNUMERIC for most things.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Today @ 10:53 AM
Points: 1,662,
Visits: 1,709
|
|
Toreador (7/6/2010)
That doesn't explain why isnumeric('1 234') = 0, despite being in the standard format for any locale with a space as the thousands separator! What I mentioned in my post was related only to the trailing spaces behavior. In other words
select cast('1234 ' as int); is fine because the trailing spaces are removed before cast kicks in, but
select cast('1 234' as int); will never fly simply because it is not a valid way to represent the number in every locale (though it is valid in some of them).
select isnumeric('1234 ') trailing_yep, isnumeric('1 234') middle_nope; returns
trailing_yep middle_nope ------------ ----------- 1 0 in the environment I use.
Oleg
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Friday, March 15, 2013 2:43 PM
Points: 3,924,
Visits: 1,554
|
|
different answer for different sql versions.
SQL 2005 and 2008 gives 21 while 2000 with nvarchar(8000) throws error
Msg 2717, Level 16, State 2, Line 1 The size (8000) given to the parameter '@String' exceeds the maximum allowed (4000). Parameter '@String' has an invalid data type.
giving varchar(8000) would give 20 answer.
20 (9), (10), (11), (12), (13), $(36), +(43), ,(44), -(45), .(46), 0(48), 1(49), 2(50), 3(51), 4(52), 5(53), 6(54), 7(55), 8(56), 9(57),
Thanks for a good question.
SQL DBA.
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Tuesday, December 07, 2010 12:55 AM
Points: 771,
Visits: 504
|
|
Excellent question. Thanks.
Also, thanks to Oleg and Duncan for their explanations.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 2:53 AM
Points: 1,528,
Visits: 359
|
|
thanks Duncan 
I also had the same issue... was getting the count 20 but didn't know why... its because of the compatibility level set to 80..
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 9:52 AM
Points: 1,356,
Visits: 4,761
|
|
Oleg Netchaev (7/6/2010)
select cast('1 234' as int);will never fly simply because it is not a valid way to represent the number in every locale (though it is valid in some of them).
that's the bit I can't understand. Does the same not apply to
isnumeric('1.234,56') yet this returns 1?
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Friday, March 22, 2013 5:58 PM
Points: 561,
Visits: 440
|
|
Toreador (7/7/2010)
that's the bit I can't understand. Does the same not apply to isnumeric('1.234,56')yet this returns 1?
I wonder if it's because ISNUMERIC disregards the position of the comma? For instance,
isnumeric('123,45.7') returns 1
As does
isnumeric('12345.67,89') I also noticed that converting a string of numbers with a comma anywhere in it (e.g., '12,345') to a numeric value results in an error, even though ISNUMERIC returns 1 on that string.
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Yesterday @ 1:07 PM
Points: 18,733,
Visits: 12,332
|
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 1:51 PM
Points: 32,906,
Visits: 26,789
|
|
Olga B (7/7/2010) I also noticed that converting a string of numbers with a comma anywhere in it (e.g., '12,345') to a numeric value results in an error, even though ISNUMERIC returns 1 on that string.
Heh... "It depends"... 
SELECT ISNUMERIC('1,2,3,4,5,6,7,8,9'), CAST('1,2,3,4,5,6,7,8,9' AS MONEY)
By definition, ISNUMERIC will return a 1 if the operand can be converted to ANY numeric value using ANY numeric datatype conversion... not just the ones you expect.
--Jeff Moden "RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".
First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Saturday, May 18, 2013 5:42 PM
Points: 15,
Visits: 78
|
|
| I'd be curious to see what the expected result is for the 21 count. I use SQL2K and long ago ended up creating my own IsNumeric function because of the issues with the native version, so assumed based on the comma issue the "right" answer was most likely 21 (comma is treated differently in SQL2K vs. SQL2K5). I read mention of the character 92, which was weird to me, and with the other variants on answers it only goes to show (IMO) the uselessness of this function
|
|
|
|