SQL Server : How to test if a string has only digit characters

后端 未结 7 1591
误落风尘
误落风尘 2021-02-05 00:59

I am working in SQL Server 2008. I am trying to test whether a string (varchar) has only digit characters (0-9). I know that the IS_NUMERIC function can give spurious results.

7条回答
  •  走了就别回头了
    2021-02-05 01:28

    The selected answer does not work.

    declare @str varchar(50)='79D136'
    
    select 1 where @str NOT LIKE '%[^0-9]%'
    

    I don't have a solution but know of this potential pitfall. The same goes if you substitute the letter 'D' for 'E' which is scientific notation.

提交回复
热议问题