How to get if a string is a number in T-SQL

后端 未结 7 1974
一向
一向 2021-01-17 12:57

Is there an easy way to get if string is an integer number (consists only of digits) in MS SQL 2005?

Thank you for your help.

7条回答
  •  Happy的楠姐
    2021-01-17 13:18

    The function ISNUMERIC returns whether a string is numeric, but will return true for non-integers.

    So you could use:

    WHERE ISNUMERIC(str) AND str NOT LIKE '%.%' AND str NOT LIKE '%e%' AND str NOT LIKE '%-%'
    

提交回复
热议问题