我还是打算用一条SQL语句实现,[xxx]表示借单主表BM中的一条借单号:update BM a set a.Estate =
(case
when b.bmoney > c.tmoney then 1
when b.bmoney = c.tmoney then 2
when b.bmoney = 0 then 0
end)
from
(select bcode, isnull(sum(bmoney),0) as bmoney from BD group by bcode) b,
(select bcode, isnull(sum(TD.tmoney),0) as tmoney from TM, TD where TM.tcode = TD.tcode group by TM.bcode) c
where
a.bcode = b.bcode
and
b.bcode = c.bcode
and
a.bcode = ['xxx']
(case
when b.bmoney > c.tmoney then 1
when b.bmoney = c.tmoney then 2
when b.bmoney = 0 then 0
end)
from
(select bcode, isnull(sum(bmoney),0) as bmoney from BD group by bcode) b,
(select bcode, isnull(sum(TD.tmoney),0) as tmoney from TM, TD where TM.tcode = TD.tcode group by TM.bcode) c
where
a.bcode = b.bcode
and
b.bcode = c.bcode
and
a.bcode = ['xxx']
(case
when c.TransactMoney = 0 then 0
when b.loanMoney > c.TransactMoney then 1
when b.loanMoney = c.TransactMoney then 2
end)
from
(select loanCode,isnull(sum(loanMoney),0) as loanMoney from TL_LoanMoneyDetail group by TL_LoanMoneyDetail.loanCode) b,
(select OrderCode,isnull(sum(TT_TransactMoneyDetail.TransactMoney),0) as TransactMoney from TT_TransactMaster,TT_TransactMoneyDetail
where TT_TransactMaster.TransactCode = TT_TransactMoneyDetail.TransactCode group by TT_TransactMaster.TransactCode) c
where
a.loanCode = b.loanCode
and
b.loanCode = c.OrderCode
and
a.loanCode = 'L20041213003'我在处理表里是用OrderCode来表示借单里的主编号loanCode的 呵呵
出错信息:
服务器: 消息 170,级别 15,状态 1,行 1
第 1 行: 'a' 附近有语法错误。
服务器: 消息 170,级别 15,状态 1,行 8
第 8 行: 'b' 附近有语法错误。
服务器: 消息 170,级别 15,状态 1,行 10
第 10 行: 'c' 附近有语法错误。
怎么回事? 都是语法错误 呵呵