I started off posting this as a question but have since realised what is happening (I think). I decided to post anyway as it's something to be aware of.
I was inserting some character data into a money column, using ISNUMERIC first to check whether it could be converted to a number. However I got an error saying that the value '3E000' could not be converted to money. For some reason that value was returning 1 from the function, ie it was saying it WAS numeric. The convert was then failing.
I was confused as according to BOL:
I tried a few other random values containing an 'E' and get the following results:
[tt]VALUE ISNUMERIC
----------------
E 0
1E 0
1E0 1
18E13 1
0E2 1[/tt]
Initially, I thought it might be something to do with HEX values but couldn't find an example where any other letter returned a 1.
I then realised that it might be reading the E as the exponential symbol in scientific number notation. Lo and behold I executed:
and got a valid result back: 3.0
So ISNUMERIC does guarantee the value can be converted into one of the numeric data types, just not necessarily all of them!
Hope this saves someone a couple of hours of exasperation (too late for me I'm afraid...) ;-)
--James
I was inserting some character data into a money column, using ISNUMERIC first to check whether it could be converted to a number. However I got an error saying that the value '3E000' could not be converted to money. For some reason that value was returning 1 from the function, ie it was saying it WAS numeric. The convert was then failing.
I was confused as according to BOL:
BOL said: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.
I tried a few other random values containing an 'E' and get the following results:
[tt]VALUE ISNUMERIC
----------------
E 0
1E 0
1E0 1
18E13 1
0E2 1[/tt]
Initially, I thought it might be something to do with HEX values but couldn't find an example where any other letter returned a 1.
I then realised that it might be reading the E as the exponential symbol in scientific number notation. Lo and behold I executed:
Code:
SELECT CAST('3E000' AS float)
and got a valid result back: 3.0
So ISNUMERIC does guarantee the value can be converted into one of the numeric data types, just not necessarily all of them!
Hope this saves someone a couple of hours of exasperation (too late for me I'm afraid...) ;-)
--James