我试图弄清楚是否可以做这样的陈述:
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)
答案 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)
)