在"

时间:2017-04-28 09:39:53

标签: sql-server tsql

我试图弄清楚是否可以做这样的陈述:

select * from telephone
where TEL_number like @tel_number
and TEL_cat in (case 
                   when @tel_number_cat = 0 
                     then 5                           
                   else 1 or 3
                 end)

有没有办法选择TEL_number如@tel_number@tel_number_cat = 0然后TEL_cat = 5 else TEL_cat = 1 or 3

是否可以在CASE条款中使用WHERE IN ()语句,但在ELSE我需要获得2类数字(1,3)

1 个答案:

答案 0 :(得分:4)

这个怎么样:

select * from telephone
where TEL_number like @tel_number
and 
(

    (TEL_cat = 5 and @tel_number_cat = 0)
    OR
    (TEL_cat IN (1,3) and @tel_number_cat <> 0)

)