Quantcast
Channel: beyondrelational.com
Viewing all articles
Browse latest Browse all 25

Understanding how ISNUMERIC function works

$
0
0

Often I hear from people that ISNUMERIC function is not working properly and there is a bug. One example people refer is that both of ISNUMERIC('12d2') and ISNUMERIC (',') return the value 1. 

Well. The definition of ISNUMERIC function is Determines whether an expression is a valid numeric type. So any expression that can be converted to numeric type is valid for ISNUMERIC to return the result as 1.
SELECT ISNUMERIC('12D2')
The result is 1. Now we can validate this using the following expression
SELECT CAST('12D2' AS FLOAT)
The result is 1200. So here the number is expressed in scientific notation and D denotes as decimal and is evaluated as 12*100 

Consider another example
SELECT ISNUMERIC(',')
The result is 1. It is because comma can be converted to MONEY datatype which can accept formatted numbers.
SELECT CAST(',' AS MONEY)
The result is 0.00 

 So next time when  you see ISNUMERIC returns 1 for an expression, it means that expression is valid for being converted to any of the numeric datatypes listedhere.

Viewing all articles
Browse latest Browse all 25

Trending Articles