SQL Server, where field is int?

前端 未结 6 418
时光说笑
时光说笑 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 04:57

    Here if you want to implement your custom function

    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
    

    ISNUMERIC returns 1 when the input expression evaluates to a valid integer, floating point number, money or decimal type; otherwise it returns 0. A return value of 1 guarantees that expression can be converted to one of these numeric types.

提交回复
热议问题