Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 IsNumeric problem

Author  Topic 

JamesT
Yak Posting Veteran

97 Posts

Posted - 2002-05-14 : 16:36:25
I have an evaluation where I use IsNumeric. The exact syntax of the evaluation is:

CASE ISNUMERIC(GOAL) WHEN 1 THEN GOAL ELSE 0 END

I get a conversion error on some columns. Specifically, the data it is returning 1 on have a + sign and a . (period) in it. IsNumeric thinks those are valid numbers. Is there a way to get around this?

Any help is appreciated.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-05-14 : 16:45:07
Well, those are legal numeric symbols. If "-1234.56" is a legal numeric value, it makes little sense to say "+1234.56" is not. There is also scientific notation, "1.234E+02" is a valid numeric value also. Not to mention the $ and other currency symbols, or commas.

As far as IsNumeric('+') and IsNumeric('.') testing positive, I agree, they shouldn't. But I think IsNumeric takes the approach of looking for any illegitimate characters that can't be converted to a number, instead of nothing but legitimate characters. That way, if it finds an illegal character, it can return right away and say "Yo, this isn't a number". Testing the rest of the value to see if it can be turned into a number is more time consuming, and wouldn't you just use CONVERT() for that anyway? (this is not my argument, just being devil's advocate) Technically, I *could* make the same argument for you using CASE in your example: IsNumeric returns 1 or 0, why use a CASE expression?

Edited by - robvolk on 05/14/2002 16:46:48
Go to Top of Page

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2002-05-15 : 05:37:16
This thread has some further exploration of the horrors of ISNUMERIC:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=13234


Edited by - Arnold Fribble on 05/15/2002 05:37:40
Go to Top of Page
   

- Advertisement -