SQL practical tips: how to determine whether a digital value method

 

Detection type data is not digital, two methods

1. ISNUMERIC ( expression )

2. PATINDEX ( ‘%pattern%‘ , expression )

1. ISNUMERIC ( expression )

If the return type is a number 1, instead of 0 is returned

But ISNUMERIC sometimes unreliable, if you do not allow expression includes any letter, will judge wrong:

Such as: ISNUMERIC ( '23e4') returns 1

   ISNUMERIC ( '23d4') returns 1

2. PATINDEX ( ‘%pattern%‘ , expression )

The return value is the first to meet the position of the pattern, if not satisfied return value is zero

Determining whether the digital type

PATINDEX ( '% [^ 0-9]%', expression)

Returns a value of 0, it is purely digital type

Support for positive and negative numbers and decimal point is written

PATINDEX ( '% [^ 0-9. | | - | +]%', expression)

Guess you like

Origin www.cnblogs.com/chenshc/p/11827682.html