Thursday, November 4, 2010

[WAT] Why I hate ISNUMERIC

So, ISNUMERIC is simple, right? Put in numbers, and it tells you whether it is.
Except it has very specific exceptions you may not know about.

Any of these will come back with ISNUMERIC = 1:
  • 0D123
  • 123D50
  • 123E50
  • $,,1,,.1

Currency doesn't count (and that's ALL currency symbols), D and E don't count in certain circumstances, commas and periods don't count.



Instead, use something like this:
if (select PATINDEX('%[^0-9.]%','$00.01')) = 0  print 'numeric' 
 
(AND DON'T  FORGET THAT IT WILL EXCLUDE NULLS) 

No comments: