SELECT t1.acctname  as '姓名',   t0.Debit-t0.Credit AS '金额', t0.Account  as '险种',    险种=       case  when left(t0.Account,8)='55010801' then '工伤险'        case  when left(t0.Account,8)='55010802' then '医疗险'end
       FROM JDT1   t0  inner join oact  t1 on t1.acctcode=t0.accountWHERE (t0.Account like '55010801%'  )  and  t0.RefDate<='2008-09-01'GROUP BY t0.Account ,t1.acctname,t0.Credit,t0.Debit
报错说是‘case附近语法错误’  帮忙看看  如何修改b

解决方案 »

  1.   

        险种=       case  when left(t0.Account,8)='55010801' then '工伤险'         when left(t0.Account,8)='55010802' then '医疗险' end 
          
      

  2.   

    SELECT t1.acctname as '姓名', t0.Debit-t0.Credit AS '金额', t0.Account as '险种', 
           险种= case when left(t0.Account,8)='55010801' then '工伤险' 
                      when left(t0.Account,8)='55010802' then '医疗险' 
                 end 
    FROM JDT1 t0 inner join oact t1 on t1.acctcode=t0.account 
    WHERE (t0.Account like '55010801%' ) and t0.RefDate <='2008-09-01' 
    GROUP BY t0.Account ,t1.acctname,t0.Credit,t0.Debit 
      

  3.   


    SELECT t1.acctname as '姓名', t0.Debit-t0.Credit AS '金额', t0.Account as '险种', 
           险种= case left(t0.Account,8) when '55010801' then '工伤险' when '55010802' then '医疗险' end 
    FROM JDT1 t0 inner join oact t1 on t1.acctcode=t0.account 
    WHERE (t0.Account like '55010801%' ) and t0.RefDate <='2008-09-01' 
    GROUP BY t0.Account ,t1.acctname,t0.Credit,t0.Debit 
      

  4.   

    多个case..
    联机丛书查查case when 的用法
      

  5.   

    SELECT t1.acctname as '姓名', t0.Debit-t0.Credit AS '金额', t0.Account as '险种', 
           险种= case left(t0.Account,8) when '55010801' then '工伤险' when '55010802' then '医疗险' end 
    FROM JDT1 t0 inner join oact t1 on t1.acctcode=t0.account 
    WHERE (t0.Account like '55010801%' ) and t0.RefDate <='2008-09-01' 
    GROUP BY t0.Account ,t1.acctname,t0.Credit,t0.Debit 
      

  6.   

    SELECT t1.acctname  as '姓名',  t0.Debit-t0.Credit AS '金额', t0.Account  as '险种',     险种=       case  when left(t0.Account,8)='55010801' then '工伤险'          when left(t0.Account,8)='55010802' then '医疗险' else 0
    end 
          FROM JDT1  t0  inner join oact  t1 on t1.acctcode=t0.account WHERE (t0.Account like '55010801%'  )  and  t0.RefDate <='2008-09-01' GROUP BY t0.Account ,t1.acctname,t0.Credit,t0.Debit