SQL Server, where field is int?

前端 未结 6 417
时光说笑
时光说笑 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:09

    select * from table
    where column_value not like '[^0-9]'
    

    If negative ints are allowed, you need something like

    where column_value like '[+-]%' 
    and substring(column_value,patindex('[+-]',substring(column_value,1))+1,len(column_value))
    not like '[^0-9]'
    

    You need more code if column_value can be an integer that exceeds the limits of the "int" type, and you want to exclude such cases.

提交回复
热议问题