2012-07-04 139 views
0

我的存儲過程是類似下面,存儲過程有錯誤

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') 

什麼語法準確的說是.....?

回答

0

我感動TransactionType =到case語句的結束。

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')