status  in (case type_order when 'A' then 30,50 when 'B' then  20,30 end)
status是int,这样写报错,应该如何写?

解决方案 »

  1.   

    select * from tb where type_order='a' and status in(30,50)
    union all
    select * from tb where type_order='b' and status in(20,30)
      

  2.   

    case返回的是一个确定的标量值,30,50这显然不是一个值
    select * from tb where (type_order='a' and status in(30,50)) or
    (type_order='b' and status in(20,30) )
      

  3.   


    把语句改一下,试试:
    and
    (case type_order when 'A' then ',30,50,' 
                     when 'B' then  ',20,30,' 
     end) like '%,'+cast(status as varchar)+',%' 
      

  4.   


    where 1=1
    and (case type_order when 'A' then status in(30,50) when 'B' then  status in(20,30) end)