开发者

problem in sql case statement?

开发者 https://www.devze.com 2023-02-19 08:34 出处:网络
select no fromshan whereaccount_number= \'7111\' andarea= \'O1139\' andty= \'1\' andty1= \'T\' anddate= \'12-AUG-10\'
     select no        
     from  shan      
     where  account_number      = '7111'
     and   area          = 'O1139'
     and   ty            = '1'
     and   ty1           = 'T'
     and   date          = '12-AUG-10'
     and   code          in (case 'B'
                             when开发者_JAVA百科 'B' then 'j01','j05'
                             when 'C' then 'j02','j06'
                             else 'j03'
                             end);

i need to check code value in 'j01' or 'j05' , how can i rewrite the query anyone please direct me in a right way?


select no from shan
where 
    account_number = '7111'
    and area          = 'O1139'
    and ty            = '1'
    and ty1           = 'T'
    and date          = '12-AUG-10'
    and ('B' = 'B' AND code in ('j01', 'j05') OR 'B' = 'C' AND code in ('j02','j06'))

case works for scalar values only.

The solution provided would be an alternative.

0

精彩评论

暂无评论...
验证码 换一张
取 消