There sql2005 the ISNUMERIC function (expression) function: When the expression is a number, returns a 0 otherwise. It's just a rookie-level solution, in most cases relatively effective.
eg:
SELECT the ISNUMERIC ( ' 123 ' ) - the result is a
However, the function has a drawback!
eg:
SELECT ,ISNUMERIC('-') as '-' --1 ,ISNUMERIC('+') as '+' --1 ,ISNUMERIC('$') as '$' --1 ,ISNUMERIC('.') as '.' --1 ,ISNUMERIC(',') as ',' --1 ,ISNUMERIC('\') as '\' --1 ,ISNUMERIC('2D3') AS '2D3'--1 ,ISNUMERIC('1d1') AS '1d1'--1 ,ISNUMERIC('1e1') AS '1e1'--1 ,ISNUMERIC('d') AS 'd' --0
When present dollar sign, a minus sign, symbols such as commas, or when D, both before and after the occurrence numbers E, also returns 1 , which is a headache. Punctuation is actually easy to understand why d, e this case, Microsoft really do not understand the intent of the design.
What is a good solution? Of course, consider the following
Methods: wildcards. High force grid use.
Applicable scene: 2005 and above (2005 version have not tried before, should also support)
- Back was pure digital 0- (support positive and negative numbers, decimal) the SELECT the PATINDEX ( ' % [^ 0-9 | | - |. +]% ' , ' 2.2 ' ) - returns 0 - Returns an integer of 0- was pure SELECT the PATINDEX ( ' % [^ 0-9]% ' , ' 2.2 ' ) - Non-zero