~SQL话语关于Where中IN后用Case,马上给分!
~~~~~~~~~SQL语句关于Where中IN后用Case,马上给分!~~~~~~~statusin (case type_order when A then 30,50
~~~~~~~~~SQL语句关于Where中IN后用Case,马上给分!~~~~~~~
status in (case type_order when 'A' then 30,50 when 'B' then 20,30 end)
status是int,这样写报错,应该如何写?
[解决办法]case返回的是一个确定的标量值,30,50这显然不是一个值
select * from tb where (type_order='a' and status in(30,50)) or
(type_order='b' and status in(20,30) )
[解决办法]把语句改一下,试试:
and
(case type_order when 'A' then ',30,50,'
when 'B' then ',20,30,'
end) like '%,'+cast(status as varchar)+',%'