SQL Server, where field is int?

前端 未结 6 468
时光说笑
时光说笑 2021-01-18 04:20

how can I accomplish:

select * from table where column_value is int

I know I can probably inner join to the system tables and type tables b

6条回答
  •  温柔的废话
    2021-01-18 05:04

    If you are purely looking to verify a string is all digits and not just CAST-able to INT you can do this terrible, terrible thing:

    select LEN(
     REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE(
     '-1.223344556677889900e-1'
     ,'0','') ,'1','') ,'2','') ,'3','') ,'4','') ,'5','') ,'6','') ,'7','') ,'8','') ,'9','')
    )
    

    It returns 0 when the string was empty or pure digits.

    To make it a useful check for "poor-man's" Integer you'd have to deal with empty string, and an initial negative sign. And manually make sure it isn't too long for your variety of INTEGER.

提交回复
热议问题