How can I query 'between' numeric data on a not numeric field?

后端 未结 4 468
别那么骄傲
别那么骄傲 2021-01-18 04:25

I\'ve got a query that I\'ve just found in the database that is failing causing a report to fall over. The basic gist of the query:

Select *
From table
Wher         


        
4条回答
  •  攒了一身酷
    2021-01-18 04:33

    Use a CASE statement.

    declare @StartRange int
    declare @EndRange int
    
    set @StartRange = 1
    set @EndRange = 3
    
    select *
    from TestData
    WHERE Case WHEN ISNUMERIC(Value) = 0 THEN 0
                WHEN Value IS NULL THEN 0
                WHEN Value = '' THEN 0
                WHEN CONVERT(int, Value) BETWEEN @StartRange AND @EndRange THEN 1
                END = 1
    

提交回复
热议问题