mysql语法中的存储过程有错误

时间:2012-07-04 17:13:22

标签: mysql

我的存储过程如下所示,

select T.TranNo,(Select Accountname from Accountable where AccountCode =T.tranAccountCode) particulars,TransactionType = case T.cate
when 'f' then 'Cash Voucher'
when 'h' then 'cash receipt'
when 'n' then 'cash receipt'
when 'o' then 'cash sale'
else 'unknowen'
end,
case when (T.TranAmount<0) then (T.TransAmount)*(-1)
End AS Credit,
case when (T.TranAmount>0) then (T.TransAmount)
end as Debit
from TranTable T where (T.TransAccountCode='1234') and (T.cate='k')

语法究竟是什么.....?

1 个答案:

答案 0 :(得分:1)

我将TransactionType =移到案例陈述的末尾。

select T.TranNo,(Select Accountname from Accountable where AccountCode =T.tranAccountCode) particulars, 
  case T.cate
    when 'f' then 'Cash Voucher'
    when 'h' then 'cash receipt'
    when 'n' then 'cash receipt'
    when 'o' then 'cash sale'
    else 'unknowen'
  end as TransactionType,
  case 
   when (T.TranAmount<0) then (T.TransAmount)*(-1)
  End AS Credit,
  case when (T.TranAmount>0) then (T.TransAmount)
  end as Debit
from TranTable T where (T.TransAccountCode='1234') and (T.cate='k')