我table表里有这样两个字段
adflag,checkflag
adflag 的值为1,2
checkflag的值为0,1
我想在checkflag = 1的时候把adflag置为0用伪码描述一下我需要的意思if checkflag = 0
   case table.adflag when 1 then 'A' else 'B' end as adflag
else
   adflag = 'C' as adflag我这样提取的目的主要是为了筛选过后用select 选取一个adflag
请问怎么在select 里面选取筛选过后的字段
   

解决方案 »

  1.   

    select adflag=(case checkflag when 0 then (case adflag when 0 then 'A' else 'B' end) else 'C' end) from [table]
      

  2.   


    SELECT checkFlag,adflad=(CASE WHEN checkflag=0 AND adflag=1 THEN 'A'
                                 WHEN checkflag=0 AND adflag<>1 THEN 'B'
                                 ELSE 'C' END)
    FROM tb
      

  3.   

    select case when checkflag = 0  then case when adflag=1 then 'A' else 'B' end else 'C' end from table1