Recently I was working with ISNUMERIC in SQL Server, when I encountered a problem, which led to finding this snippet of code.
SELECT ISNUMERIC('.')
This returns 1, as in true, shouldn’t this return 0 as in false?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
See IsNumeric() Broken? Only up to a point.
returns
0.00(though the cast fails forintandfloat)ISNUMERICjust checks that the value can be cast to any one of the numeric datatypes which is generally useless. Usually you want to know whether it can be cast to a specific type.Additionally it doesn’t even seem to do that task correctly for all possible inputs..
ISNUMERIC(' ')returns0despite casting successfully to both int and money. ConverselyISNUMERIC(N'8')returns1but does not cast successfully to anything that I tried.Some useful helper functions for that are here IsNumeric, IsInt, IsNumber.
SQL Server 2012 introduced
TRY_PARSEandTRY_CONVERTthat help with this greatly.