我们如何在 WHERE 子句中指定 CASE 的值范围?
我的这个查询失败了
declare @ProductType int
select * from Products
where ProductLine in
(
case @ProductType
when 1 then ('TVs')
when 2 then ('Handsets', 'Mobiles') --fails here
else ('Books')
end
)
这也行不通:
declare @ProductType int
select * from Products
where (case @ProductType
when 1 then (ProductLine = 'TVs')
when 2 then (ProductLine in ('Handsets', 'Mobiles'))
else (ProductLine = 'Books')
end)