SQL Server, where field is int?

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

    I would do a UDF as Svetlozar Angelov suggests, but I would check for ISNUMERIC first (and return 0 if not), and then check for column_value % 1 = 0 to see if it's an integer.

    Here's what the body might look like. You have to put the modulo logic in a separate branch because it will throw an exception if the value isn't numeric.

    DECLARE @RV BIT
    IF ISNUMERIC(@value) BEGIN
        IF CAST(@value AS NUMERIC) % 1 = 0 SET @RV = 1
        ELSE SET @RV = 0
    END
    ELSE SET @RV = 0
    RETURN @RV
    

提交回复
热议问题