﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Ron Moses  / More fun with ISNUMERIC() / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 23 May 2013 15:04:34 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>Nice question.  I particularly liked the inclusion of the string in the final select, so that people could see what was going on.Surprised by some of the comments - I though everyone would know the what the character codes in the 9 to 13 range represent, I guess some of teh youngsters never needed to know that stuff because (a) modern text handling tools are a bit higher level that some of the old ones and (b) people stopped reading punched tape maybe 30 years ago.</description><pubDate>Sat, 18 Sep 2010 13:10:50 GMT</pubDate><dc:creator>L' Eomot Inversé</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>It does as the MSDN says,ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/uas9/html/5193c976-9dcd-459c-abba-8c3c44e7a7f2.htm ISNUMERIC returns 1 for some characters that are not numbers, such as plus (+), minus (-), and valid currency symbols such as the dollar sign ($). For a complete list of currency symbols.</description><pubDate>Thu, 15 Jul 2010 12:31:07 GMT</pubDate><dc:creator>jawad.zubairi</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>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</description><pubDate>Wed, 07 Jul 2010 21:57:33 GMT</pubDate><dc:creator>pparsons</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>[quote][b]Olga B (7/7/2010)[/b][hr]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.[/quote]Heh... "It depends"... ;-)[code="sql"] SELECT ISNUMERIC('1,2,3,4,5,6,7,8,9'),        CAST('1,2,3,4,5,6,7,8,9' AS MONEY)[/code]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.</description><pubDate>Wed, 07 Jul 2010 18:14:48 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>thanks for the QOD</description><pubDate>Wed, 07 Jul 2010 14:56:04 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>[quote][b]Toreador (7/7/2010)[/b][hr]that's the bit I can't understand. Does the same not apply to[code="sql"]isnumeric('1.234,56')[/code]yet this returns 1?[/quote]I wonder if it's because ISNUMERIC disregards the position of the comma? For instance, [code="sql"]isnumeric('123,45.7')[/code]returns 1As does[code="sql"]isnumeric('12345.67,89')[/code]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.</description><pubDate>Wed, 07 Jul 2010 13:42:12 GMT</pubDate><dc:creator>Olga B</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>[quote][b]Oleg Netchaev (7/6/2010)[/b][hr][code="sql"]select cast('1 234' as int);[/code]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).[/quote]that's the bit I can't understand. Does the same not apply to[code="sql"]isnumeric('1.234,56')[/code]yet this returns 1?</description><pubDate>Wed, 07 Jul 2010 02:14:17 GMT</pubDate><dc:creator>Toreador</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>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..</description><pubDate>Wed, 07 Jul 2010 00:30:15 GMT</pubDate><dc:creator>ziangij</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>Excellent question.  Thanks.Also, thanks to Oleg and Duncan for their explanations.</description><pubDate>Tue, 06 Jul 2010 16:08:04 GMT</pubDate><dc:creator>KevinC.</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>different answer for different sql versions.SQL 2005 and 2008 gives 21 while 2000 with nvarchar(8000) throws errorMsg 2717, Level 16, State 2, Line 1The 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), &#xB;(11), &#xC;(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.</description><pubDate>Tue, 06 Jul 2010 12:32:35 GMT</pubDate><dc:creator>SanjayAttray</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>[quote][b]Toreador (7/6/2010)[/b][hr]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![/quote]What I mentioned in my post was related only to the trailing spaces behavior. In other words [code="sql"]select cast('1234      ' as int);[/code]is fine because the trailing spaces are removed before cast kicks in, but[code="sql"]select cast('1 234' as int);[/code]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).[code="sql"]select 	isnumeric('1234     ') trailing_yep, 	isnumeric('1 234') middle_nope;[/code]returns [code="sql"]trailing_yep middle_nope------------ -----------1            0[/code]in the environment I use.Oleg</description><pubDate>Tue, 06 Jul 2010 11:17:30 GMT</pubDate><dc:creator>Oleg Netchaev</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>Nice questions thanks! Yet more reasons to not use ISNUMERIC for most things.</description><pubDate>Tue, 06 Jul 2010 11:13:47 GMT</pubDate><dc:creator>UMG Developer</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>[quote][b]Oleg Netchaev (7/6/2010)[/b][hr]I think what is happening here is the following: isnumeric('') = 0 and because the trailing spaces are truncated when the strings are compared, i.e. '' = ' ' = '   ' etc, the isnumeric(char(32)) evaluates to isnumeric('') which is known to return 0. This means that isnumeric('any_number_of_spaces_here') is equal to 0 because the trailing spaces are first removed. char(160) is not considered a space (so it is not removed before isnumeric kicks in) though it prints identically with one. Oleg[/quote]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!</description><pubDate>Tue, 06 Jul 2010 10:17:06 GMT</pubDate><dc:creator>Toreador</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>[quote][b]paul.knibbs (7/5/2010)[/b][hr]I was expecting an answer of 14 (numbers 0-9, +, -, . and $), but of course that wasn't an option, so I had to go and run the script to find out where I was wrong. I can see why , counts as numeric, but some of the other values that count as such are a bit baffling--characters 9, 11, and 12, for instance![/quote]Agreed.  I chose 16, figuring I must have missed a decimal- or currency-related symbol.  Certainly didn't expect 9-13 to show up as "numeric"s!  Thanks to the questioner for the QotD.</description><pubDate>Tue, 06 Jul 2010 10:13:56 GMT</pubDate><dc:creator>Michael Poppers</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>This is a very good question, thank you Ron. It really took some time to figure out correct answer. From your explanation:[quote]Odd that running ISNUMERIC() against a space (ASCII 32) returns 0, but a non-breaking space (ASCII 160) returns a 1, eh? [/quote]I think what is happening here is the following: isnumeric('') = 0 and because the trailing spaces are truncated when the strings are compared, i.e. '' = ' ' = '   ' etc, the isnumeric(char(32)) evaluates to isnumeric('') which is known to return 0. This means that isnumeric('any_number_of_spaces_here') is equal to 0 because the trailing spaces are first removed. char(160) is not considered a space (so it is not removed before isnumeric kicks in) though it prints identically with one. Oleg</description><pubDate>Tue, 06 Jul 2010 09:58:49 GMT</pubDate><dc:creator>Oleg Netchaev</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>[quote][b]Kari Suresh (7/5/2010)[/b][hr][p]Thanks Duncan. You are right, master DB is in compatibility level 80 and other databases are in compatibility level 90.[/p][/quote]No problem. Glad to help.Duncan</description><pubDate>Tue, 06 Jul 2010 00:35:40 GMT</pubDate><dc:creator>Duncan Pryde</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>[quote][b]savosin_sergey (7/5/2010)[/b][hr]Thank you, Duncan, you've right - my tempdb at compatibility_level=90 and the query from task returns 21, though my test database has compatibility_level=80[/quote]And thank you for noticing the behaviour in the first place!Duncan</description><pubDate>Tue, 06 Jul 2010 00:34:30 GMT</pubDate><dc:creator>Duncan Pryde</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>[quote]As I mentioned above, that's almost certainly because your master database is in compatibility level 80 (SQL 2000), while your other databases are in compatibility level 90 or 100 (SQL 2005 or 2008).Do check and let me know.[/quote][p]Thanks Duncan. You are right, master DB is in compatibility level 80 and other databases are in compatibility level 90.[/p]</description><pubDate>Mon, 05 Jul 2010 23:41:08 GMT</pubDate><dc:creator>Kari Suresh</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>[quote][b]Duncan Pryde (7/5/2010)[/b][hr]Looks like a compatibility level issue. If you set the database to SQL Server 2000 compatibility mode, you lose the backslash character (92) from the list. Something to do with it being a valid currency character only in Japan/Korea for SQL 2000 but for all countries in SQL 2005-8.See about half way down [url=http://msdn.microsoft.com/en-us/library/bb510680.aspx][u]this page[/u][/url]Duncan[/quote]Thank you, Duncan, you've right - my tempdb at compatibility_level=90 and the query from task returns 21, though my test database has compatibility_level=80</description><pubDate>Mon, 05 Jul 2010 22:34:28 GMT</pubDate><dc:creator>savosin_sergey</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>BOL simply state [quote]ISNUMERIC returns 1 for some characters that are not numbers, such as plus (+), minus (-), and valid currency symbols such as the dollar sign ($). For a complete list of currency symbols, see Using Monetary Data.[/quote] Honestly, I am used to better quality of Microsoft's product manuals. Documentation of this kind should be left to Oracle.;-)</description><pubDate>Mon, 05 Jul 2010 12:18:33 GMT</pubDate><dc:creator>Dietmar Weickert</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>OK, I looked up an [url=http://www.asciitable.com/]ASCII table[/url], and characters 11 &amp; 12 are supposed to be white space type characters.  How many people are finding SSMS 2008 printing the two interesting characters I got "♂(11), ♀(12),"?</description><pubDate>Mon, 05 Jul 2010 09:38:10 GMT</pubDate><dc:creator>JediSQL</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>I got the 43 - 57 stuff, and expected some white space, but what's with 11 &amp; 12???  Do they go with the monetary data types because some people are willing to pay for them? :w00t:They are not described in BOL.</description><pubDate>Mon, 05 Jul 2010 09:16:06 GMT</pubDate><dc:creator>JediSQL</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>[quote][b]Kari Suresh (7/5/2010)[/b][hr][p]This query returns count as 20 when executing against "master" DB (excluding '\' ASCII character number 92) and returns 21 when executing with other databases.[/p][/quote]As I mentioned above, that's almost certainly because your master database is in compatibility level 80 (SQL 2000), while your other databases are in compatibility level 90 or 100 (SQL 2005 or 2008).Do check and let me know.Duncan</description><pubDate>Mon, 05 Jul 2010 08:13:22 GMT</pubDate><dc:creator>Duncan Pryde</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>[p]This query returns count as 20 when executing against "master" DB (excluding '\' ASCII character number 92) and returns 21 when executing with other databases.[/p]</description><pubDate>Mon, 05 Jul 2010 07:53:39 GMT</pubDate><dc:creator>Kari Suresh</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>Great question by the way, thanks!Duncan</description><pubDate>Mon, 05 Jul 2010 05:22:55 GMT</pubDate><dc:creator>Duncan Pryde</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>[quote][b]savosin_sergey (7/5/2010)[/b][hr]My Count is only 20 (while right answer is 21)! Here is text result of the query from Question:[code="plain"]Count       String----------- -----------20          	(9), (10), &#xB;(11), &#xC;(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), [/code](1 row(s) affected)[/quote]Looks like a compatibility level issue. If you set the database to SQL Server 2000 compatibility mode, you lose the backslash character (92) from the list. Something to do with it being a valid currency character only in Japan/Korea for SQL 2000 but for all countries in SQL 2005-8.See about half way down [url=http://msdn.microsoft.com/en-us/library/bb510680.aspx][u]this page[/u][/url]Duncan</description><pubDate>Mon, 05 Jul 2010 05:20:40 GMT</pubDate><dc:creator>Duncan Pryde</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>I was expecting an answer of 14 (numbers 0-9, +, -, . and $), but of course that wasn't an option, so I had to go and run the script to find out where I was wrong. I can see why , counts as numeric, but some of the other values that count as such are a bit baffling--characters 9, 11, and 12, for instance!</description><pubDate>Mon, 05 Jul 2010 03:30:08 GMT</pubDate><dc:creator>paul.knibbs</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>I've just changed my Regional Settings to French, so the thousands seperator is a space. But even now, IsNumeric('1 234') returns 0.I knew there was a good reason that I avoid this function!</description><pubDate>Mon, 05 Jul 2010 02:35:29 GMT</pubDate><dc:creator>Toreador</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>My Count is only 20 (while right answer is 21)! Here is text result of the query from Question:[code="plain"]Count       String----------- -----------20          	(9), (10), &#xB;(11), &#xC;(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), [/code](1 row(s) affected)</description><pubDate>Mon, 05 Jul 2010 00:25:07 GMT</pubDate><dc:creator>savosin_sergey</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>Doesn't explain why chr(13) is numeric... what function. Nice question.</description><pubDate>Mon, 05 Jul 2010 00:15:55 GMT</pubDate><dc:creator>ma-516002</dc:creator></item><item><title>RE: More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>Hello!For those who are interested in an official documentation on this behaviour, refer BOL at: http://msdn.microsoft.com/en-us/library/ms186272.aspxThank-you!</description><pubDate>Sun, 04 Jul 2010 03:46:29 GMT</pubDate><dc:creator>Nakul Vachhrajani</dc:creator></item><item><title>More fun with ISNUMERIC()</title><link>http://www.sqlservercentral.com/Forums/Topic947263-1694-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/questions/T-SQL/70135/"&gt;More fun with ISNUMERIC()&lt;/A&gt;[/B]</description><pubDate>Sat, 03 Jul 2010 14:25:11 GMT</pubDate><dc:creator>ronmoses</dc:creator></item></channel></rss>