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

后端 未结 7 1911
一向
一向 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条回答
  •  时光说笑
    2021-01-17 13:14

    See this:

    CREATE Function dbo.IsInteger(@Value VarChar(18))
    Returns Bit
    As 
    Begin
    
      Return IsNull(
     (Select Case When CharIndex('.', @Value) > 0 
                  Then Case When Convert(int, ParseName(@Value, 1)) <> 0
                            Then 0
                            Else 1
                            End
                  Else 1
                  End
          Where IsNumeric(@Value + 'e0') = 1), 0)   
    
    End
    

提交回复
热议问题