views:

60

answers:

4

ISNUMERIC returns 1 when the input expression evaluates to a valid numeric data type; otherwise it returns 0 (MSDN reference).

So why is the output of this query 1?

select ISNUMERIC('5d9')
A: 

Hexa : 5d9 <==> Decimal : 1497

Spilarix
5a9 isn't, so this falls down.
spender
@spender: yeap, the first thing I tried when I saw the question was `5f9` with no luck. `5e9` works though... `e` is probably exponential notation but `d`?
Diadistis
+2  A: 

Not sure bit taking a shot at it!! :-)

ISNUMERIC returns 1 when the input expression evaluates to a valid integer, floating point number, money or decimal type

I think that in this case, it is considering the "d" to stand for decimal and hence considering it to be a number.

I think 5e9 should be similar as well as "e" is also used mathematically to denote exponent..Dont have SQL here to try it out right now..but i think result of 5e9 should be 1 for the same reason

EDIT : Some more context here (result of some quick googling!!)

InSane
5e9 is numeric. Good answer. +1
spender
Hmm... select cast('5d9' as int) fails. What a mess.
spender
+1  A: 
select cast('5d9' as float)

Returns

5000000000

d appears to work in the same manner as e

Martin Smith
+1  A: 

ISNUMERIC() has no practical use and should generally be avoided.

It tells you if a string can be converted to a numeric data type but, as you saw, that can include seemingly random characters. eg. it can also include +, -, $, etc.

(obviously, they're not random, but if you're using ISNUMERIC() for validation, you'll struggle to find a case where you want to allow all possibilities it allows)

Paul Spangle

related questions