Quote:
quote:Originally posted by SubodhKumar
<snippage>
Actually characters like dollar($),comma(,) and dot(.) is used to represent numberic data.
E.g.
$5000.00
5000.75
56,775.00
thats why these character is treated as numeric data.
Obviously the output is not desired.To get the desired result we can write our query like:-
select fld,case
when fld like '%.%' then 0
when fld like '%,%' then 0
when fld like '%$%' then 0
else isnumeric(fld)
end as 'IsNumeric'
from temps
it will give correct output :-
|
Nope.
Your WHERE criteria would reject a valid numeric string like 19.25 as non numeric.
This is actually an interesting issue. From BOL:
"ISNUMERIC returns 1 when the input expression evaluates to a valid integer, floating point number, money or decimal type; otherwise it returns 0. A return value of 1 guarantees that expression can be converted to one of these numeric types".
Apparently, the rule is whether the CAST function would throw an error attempting to convert the string to one of the numeric types. Many seemingly invalid numeric strings in fact result in a ISNUMERIC value of 1. For example, these strings all result in a 1:
.
,
,.
.,
$.
$,.
$,9.
9,9. --!!! this will CAST to money as 99.0000
etc. etc.
because you can CAST each of these strings to a money type and you get a "reasonable" value, e.g. CAST('.' as money) results in a value of .0000.
What's weird is that if you attempt to CAST the same string to any other type (like decimal) you'll get a conversion error. What's even worse, the string '1E10' will return a 1, but a CAST to money will result in a conversion error. Of course, that string will successfully CAST to FLOAT.
Unfortunately, it seems ISNUMERIC doesn't tell you
which numeric type it can successfully CAST to, only that it
can make
some successful CAST...
I think this is a flaw in the definition and behavior of ISNUMERIC, and I have no good solution, short of writing an ugly user defined function which makes use of the LIKE operator and other string operators to parse your string into what you would define as a valid numeric string, and not what SQL Server ISNUMERIC does...
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com