Thursday, March 26, 2009

IsNumeric?

Finally a technical blog. J

I had used IsNumeric functions of MSSQL in my stored proc. I was supposed to do some other actions based on the results of IsNumeric function.

If IsNumeric(@var)=1

Select ‘True’

Else

Select ‘False’


Surprising and shockingly I found strange results. Here’s the sample. Note down your answers before you check the output of the below 3 statements.


Select IsNumeric(‘1D’)

Select IsNumeric(‘D1’)

Select IsNumeric(‘1D1’)


Yes, the SQL treats ‘1D1’ as numeric.

This happens with only 2 letters ‘D’ and ‘E’.

If the entire string which is used for check has only one character and that one character is either ‘D’ or ‘E’ then the string is considered as numeric.


I am not very sure about the reason behind this behavior of SQL.

If anyone has answer for this please comment it to my post.