解决方案: |
执行如下SQL语句即可(执行前作好备份):
UPDATE TOTAL
SET dblTransOutDeprTotal = TOLdblDebitDepr
FROM
(SELECT CARDS.sDeptNum,CARDS.sTypeNum,
SUM(dblDebitDepr) AS TOLdblDebitDeprFROM
(SELECT fa_Cards.lOptID,
SUM(CONVERT(float,sBeforeVoucher)) AS sBeforeVoucher,
SUM(CONVERT(float,sAfterVoucher)) AS sAfterVoucher,
SUM(CONVERT(float,sBeforeVoucher))-SUM(CONVERT(float,sAfterVoucher)) AS dblDebitDepr
FROM fa_Cards INNER JOIN fa_Vouchers_Detail
ON fa_Cards.sVoucherNum = fa_Vouchers_Detail.sNum
WHERE (((fa_Cards.iTransPeriod) Between 3 And 3)
AND ((fa_Cards.sTypeNum) Like ‘%‘)
AND ((fa_Vouchers_Detail.sDeptNum) Like ‘%‘)
AND ((fa_Cards.iOptType)=4 Or (fa_Cards.iOptType)=5 Or (fa_Cards.iOptType)=11))
GROUP BY fa_Cards.lOptID) AS AA
INNER JOIN FA_CARDS AS CARDS
ON AA.LOPTid = CARDS.LOPTID
WHERE CARDS.IOPTTYPE=11
GROUP BY CARDS.sDeptNum,CARDS.sTypeNum) AS TOL
INNER JOIN FA_TOTAL AS TOTAL
ON TOL.sDeptNum=TOTAL.sDeptNum
AND TOL.sTypeNum = TOTAL.sTypeNum
WHERE TOTAL.iPeriod=3 |