As mentioned – casually – in the msdn documentation the IsNumeric function will return 1 for some values which aren’t actually numbers. The currency sign $ is mentioned as well are plus/minus.
Period and comma will also be returning 1.
This essentially means that you can’t be sure that it is actually a number/numeric value which passes the IsNumeric check.
And least of all, you can’t be assured of the semantic value returned is what you expect.
This can – if unaware and not paying attention – be a problem when dealing with number values for countries which do not follow the same period/decimal convention as the US.
Also – “funnily” enough due to the caveats in the IsNumeric, you can’t actually be assured that it can be converted to a Numeric data type. (It can normally always be converted into a Money, but then the name is misleading
)
To illustrate notice for example the following snippet:
DECLARE @VAR VARCHAR(20)
SET @VAR = ‘€,.,,’
This will pass a “IsNumeric” check with the result 1, but it can’t be cast into a numeric/decimal. It can be cast into money but will return 0.00
And that is despite it is not in any form an actual numeric value.
There are some semantic checks built into the IsNumeric such as you can’t have values infront of the currency sign, so
SET @VAR = ’123$’
would fail a “IsNumeric” check. Also some checks on the numbers of “plus/minus” signs and so on……
So when using IsNumeric, it is time to be careful and not just accept a success for actual success.
Thank you for another awesome blog post. Kind regards, Alice Williams @ parmar