SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


ISNUMERIC


ISNUMERIC

Author
Message
chgn01
chgn01
SSCrazy
SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)

Group: General Forum Members
Points: 2032 Visits: 1898
Comments posted to this topic are about the item ISNUMERIC

--------------------------------------
;-)“Everything has beauty, but not everyone sees it.” ― Confucius
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64959 Visits: 18570
Thanks for the question.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

Dineshbabu
Dineshbabu
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1430 Visits: 569
Again making the trick with length of the column.. Nice ..

--
Dineshbabu
Desire to learn new things..
kapil_kk
kapil_kk
SSCertifiable
SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)

Group: General Forum Members
Points: 5214 Visits: 2767
Good Question but still I have doubts in some cases like:

SELECT ISNUMERIC('.+') -- Returns 0
SELECT ISNUMERIC('+.') -- Returns 1
SELECT ISNUMERIC (',\') -- Returns 0
SELECT ISNUMERIC ('\,') -- Returns 1

Ermm

_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Danny Ocean
Danny Ocean
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2200 Visits: 1549
+1 :-)

Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
www.GrowWithSql.com
Hugo Kornelis
Hugo Kornelis
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18489 Visits: 12426
An okay question, I guess. The combination of title, question, and answer options may make it very easy to overlook the actual issue, but if we cannot be expected to read code carefully, who can?

But really a shame that the explanation totally fails ijn explaining the correct answer. At first sight, all zeroes appears to be the correct answer, because the string fragment "NAME" makes all of the string constants in the INSERT statements non-numeric. Too bad the author of the question failed to include the explanation that this string fragment is just a distracter - the string column is declared to be varchar(2), so in all those cases the offending characters are stripped off.

Another relevant part of the explanation is missing as well, as is demonstrated by kapil_kk:
kapil_kk (4/7/2013)
Good Question but still I have doubts in some cases like:

SELECT ISNUMERIC('.+') -- Returns 0
SELECT ISNUMERIC('+.') -- Returns 1
SELECT ISNUMERIC (',\') -- Returns 0
SELECT ISNUMERIC ('\,') -- Returns 1

Ermm

I can help him to some extent, but not fully. I can explain the first two, and IO'm going to do that in reversed order.

SELECT ISNUMERIC('+.') -- Returns 1
That is because just . is a valid numeric (represents 0.0). A trailing zero after a decimal point can be left out - nobody is surprised by 3. being equal to 3.0. A leading zero is also optional, we all write 3.1 instead of 003.1, and we all have seen numbers starting with a dot, like .31 instead of 0.31. What is unusual is both zeroes being removed at the same time - but if the number is 0.0 and the leading and trailing zeroes are removed, all that's left is a dot.
And a plus sign before a number is also valid. We hardly ever use it - we are used to starting the number with a minus sign for negative, and omitting the plus sign for positive numbers. But it is valid to include it.
Combine 0.0 represented as . with a leading plus sign, and you get +.

SELECT ISNUMERIC('.+') -- Returns 0
After the above explanation, this one is a lot shorter. A plus sign is only valid at the first non-blank position. Just as a negative. We al,low -13.14, but we frown upon 3-1.14, 31-.14, 31.1-4, and 31.14- (though the latter is sometimes usesd by bankers and accountants).


I hope someone else can explain why a backslash at the start of the string is considered numeric, as I was surprised at that myself.


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
kapil_kk
kapil_kk
SSCertifiable
SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)

Group: General Forum Members
Points: 5214 Visits: 2767
Hugo Kornelis (4/8/2013)
An okay question, I guess. The combination of title, question, and answer options may make it very easy to overlook the actual issue, but if we cannot be expected to read code carefully, who can?

But really a shame that the explanation totally fails ijn explaining the correct answer. At first sight, all zeroes appears to be the correct answer, because the string fragment "NAME" makes all of the string constants in the INSERT statements non-numeric. Too bad the author of the question failed to include the explanation that this string fragment is just a distracter - the string column is declared to be varchar(2), so in all those cases the offending characters are stripped off.

Another relevant part of the explanation is missing as well, as is demonstrated by kapil_kk:
kapil_kk (4/7/2013)
Good Question but still I have doubts in some cases like:

SELECT ISNUMERIC('.+') -- Returns 0
SELECT ISNUMERIC('+.') -- Returns 1
SELECT ISNUMERIC (',\') -- Returns 0
SELECT ISNUMERIC ('\,') -- Returns 1

Ermm

I can help him to some extent, but not fully. I can explain the first two, and IO'm going to do that in reversed order.

SELECT ISNUMERIC('+.') -- Returns 1
That is because just . is a valid numeric (represents 0.0). A trailing zero after a decimal point can be left out - nobody is surprised by 3. being equal to 3.0. A leading zero is also optional, we all write 3.1 instead of 003.1, and we all have seen numbers starting with a dot, like .31 instead of 0.31. What is unusual is both zeroes being removed at the same time - but if the number is 0.0 and the leading and trailing zeroes are removed, all that's left is a dot.
And a plus sign before a number is also valid. We hardly ever use it - we are used to starting the number with a minus sign for negative, and omitting the plus sign for positive numbers. But it is valid to include it.
Combine 0.0 represented as . with a leading plus sign, and you get +.

SELECT ISNUMERIC('.+') -- Returns 0
After the above explanation, this one is a lot shorter. A plus sign is only valid at the first non-blank position. Just as a negative. We al,low -13.14, but we frown upon 3-1.14, 31-.14, 31.1-4, and 31.14- (though the latter is sometimes usesd by bankers and accountants).


I hope someone else can explain why a backslash at the start of the string is considered numeric, as I was surprised at that myself.

Thanks Hugo for the explanation :-)
For the first part I understand the behavior but am still confused with the SELECT ISNUMERIC('.+') -- Returns 0 behavior Sad

I am again surprised with these two statements behavior:
SELECT ISNUMERIC('.,') -- Return 1
SELECT ISNUMERIC(',.') -- Return 1

I hope someone can explain to us about these two statements behavior.

_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Hugo Kornelis
Hugo Kornelis
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18489 Visits: 12426
kapil_kk (4/8/2013)
For the first part I understand the behavior but am still confused with the SELECT ISNUMERIC('.+') -- Returns 0 behavior Sad

The . actually represents 0.0, with leading and trailing zero omitted.
So +. is equivalent to +0.0, which is a valid number. But .+ is equivalent to 0.0+, which is not. The plus sign (just as the minus sign) is only valid at the start of the numeric string.

I am again surprised with these two statements behavior:
SELECT ISNUMERIC('.,') -- Return 1
SELECT ISNUMERIC(',.') -- Return 1

The comma is used as the thousands seperator in America (and, as far as I know, most English speaking countries). When converting from string to money and smallmoney, thousands seperators in the string are accepted. This is implemented in a rather loose way - there is no checkk if the thousands seperators are where they should be, they are simply ignored.


Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
kapil_kk
kapil_kk
SSCertifiable
SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)SSCertifiable (5.2K reputation)

Group: General Forum Members
Points: 5214 Visits: 2767
Hugo Kornelis (4/8/2013)
kapil_kk (4/8/2013)
For the first part I understand the behavior but am still confused with the SELECT ISNUMERIC('.+') -- Returns 0 behavior Sad

The . actually represents 0.0, with leading and trailing zero omitted.
So +. is equivalent to +0.0, which is a valid number. But .+ is equivalent to 0.0+, which is not. The plus sign (just as the minus sign) is only valid at the start of the numeric string.

I am again surprised with these two statements behavior:
SELECT ISNUMERIC('.,') -- Return 1
SELECT ISNUMERIC(',.') -- Return 1

The comma is used as the thousands seperator in America (and, as far as I know, most English speaking countries). When converting from string to money and smallmoney, thousands seperators in the string are accepted. This is implemented in a rather loose way - there is no checkk if the thousands seperators are where they should be, they are simply ignored.

Thanks Hugo, now its clear to me :-):-)

_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
nenad-zivkovic
nenad-zivkovic
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1184 Visits: 786
I hope someone else can explain why a backslash at the start of the string is considered numeric, as I was surprised at that myself.


I've managed to find this info:

http://msdn.microsoft.com/en-us/library/bb510680(v=sql.100).aspx

The backslash character (\) is accepted in all string to money conversions in all languages. ISNUMERIC would return true when \ is used as a currency symbol.


http://blogs.msdn.com/b/michkap/archive/2005/10/12/479561.aspx

_______________________________________________
www.sql-kefalo.net (SQL Server saveti, ideje, fazoni i fore)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search