修复常规页面和明细数据对不上的BUG

2017/05/16 15:08:23
/*
特别说明:此脚本只适用于Q7+的版本
*/


--捡货单
update PickingH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from PickingH H INNER JOIN (SELECT cPickingCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM PickingDS GROUP BY cPickingCode) D ON H.cPickingCode = D.cPickingCode

--订单
update OrderH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from OrderH H INNER JOIN (SELECT cOrderCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM OrderDS GROUP BY cOrderCode) D ON H.cOrderCode = D.cOrderCode


--代销结算单
update AgentRetailH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from AgentRetailH H INNER JOIN (SELECT cAgentRetailCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM AgentRetailDS GROUP BY cAgentRetailCode) D ON H.cAgentRetailCode = D.cAgentRetailCode


--条码申请单
update BarcodeApplyH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from BarcodeApplyH H INNER JOIN (SELECT cBarcodeApplyCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM BarcodeApplyDS GROUP BY cBarcodeApplyCode) D ON H.cBarcodeApplyCode = D.cBarcodeApplyCode

--条码打印单
update BarcodePrintH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from BarcodePrintH H INNER JOIN (SELECT cBarcodePrintCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM BarcodePrintDS GROUP BY cBarcodePrintCode) D ON H.cBarcodePrintCode = D.cBarcodePrintCode

--渠道调入单
update BMoveInH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from BMoveInH H INNER JOIN (SELECT cMoveInCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM BMoveInDS GROUP BY cMoveInCode) D ON H.cMoveInCode = D.cMoveInCode


--渠道调出单
update BMoveOutH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from BMoveOutH H INNER JOIN (SELECT cMoveOutCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM BMoveOutDS GROUP BY cMoveOutCode) D ON H.cMoveOutCode = D.cMoveOutCode

--渠道调出通知单
update BMoveOutAdviceH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from BMoveOutAdviceH H INNER JOIN (SELECT cMoveOutAdvCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM BMoveOutAdviceDS GROUP BY cMoveOutAdvCode) D ON H.cMoveOutAdvCode = D.cMoveOutAdvCode

--库存期初单
update StockFirstH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from StockFirstH H INNER JOIN (SELECT cStockFirstCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM StockFirstDS GROUP BY cStockFirstCode) D ON H.cStockFirstCode = D.cStockFirstCode

--盘点单
update CheckH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from CheckH H INNER JOIN (SELECT cCheckCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM CheckDS GROUP BY cCheckCode) D ON H.cCheckCode = D.cCheckCode

--销售出货单
update DeliveryH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from DeliveryH H INNER JOIN (SELECT cDeliCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM DeliveryDS GROUP BY cDeliCode) D ON H.cDeliCode = D.cDeliCode

--渠道收货单
update DeliveryInH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from DeliveryInH H INNER JOIN (SELECT cDeliInCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM DeliveryInDS GROUP BY cDeliInCode) D ON H.cDeliInCode = D.cDeliInCode

--差异通知单
update DifAdviceH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from DifAdviceH H INNER JOIN (SELECT cDifAdvCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM DifAdviceDS GROUP BY cDifAdvCode) D ON H.cDifAdvCode = D.cDifAdvCode

--渠道收退货单
update DeliveryReturnH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from DeliveryReturnH H INNER JOIN (SELECT cDeliRetCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM DeliveryReturnDS GROUP BY cDeliRetCode) D ON H.cDeliRetCode = D.cDeliRetCode

--拣货单
update PickingH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from PickingH H INNER JOIN (SELECT cPickingCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM PickingDS GROUP BY cPickingCode) D ON H.cPickingCode = D.cPickingCode

--库存调整单
update ProfitLossH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from ProfitLossH H INNER JOIN (SELECT cPlCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM ProfitLossDS GROUP BY cPlCode) D ON H.cPlCode = D.cPlCode

--采购单
update PurchaseH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from PurchaseH H INNER JOIN (SELECT cPurCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM PurchaseDS GROUP BY cPurCode) D ON H.cPurCode = D.cPurCode

--配货单
update RationH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from RationH H INNER JOIN (SELECT cRationCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM RationDS GROUP BY cRationCode) D ON H.cRationCode = D.cRationCode

--采购收货单
update ReceiptH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from ReceiptH H INNER JOIN (SELECT cRecCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM ReceiptDS GROUP BY cRecCode) D ON H.cRecCode = D.cRecCode

--渠道退货审批单
update ReturnAdviceH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from ReturnAdviceH H INNER JOIN (SELECT cRetAdvCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM ReturnAdviceDS GROUP BY cRetAdvCode) D ON H.cRetAdvCode = D.cRetAdvCode

--渠道退货申请单
update ReturnApplyH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from ReturnApplyH H INNER JOIN (SELECT cRetApplyCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM ReturnApplyDS GROUP BY cRetApplyCode) D ON H.cRetApplyCode = D.cRetApplyCode

--渠道退货单
update ReturnInH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from ReturnInH H INNER JOIN (SELECT cRetInCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM ReturnInDS GROUP BY cRetInCode) D ON H.cRetInCode = D.cRetInCode

--采购退货单
update VReturnH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from VReturnH H INNER JOIN (SELECT cRetVCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM VReturnDS GROUP BY cRetVCode) D ON H.cRetVCode = D.cRetVCode

--厂家到货通知单
update VAdviceH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from VAdviceH H INNER JOIN (SELECT cAdvVCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM VAdviceDS GROUP BY cAdvVCode) D ON H.cAdvVCode = D.cAdvVCode

--采购退货通知单
update VReturnAdviceH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from VReturnAdviceH H INNER JOIN (SELECT cRetAdvVCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM VReturnAdviceDS GROUP BY cRetAdvVCode) D ON H.cRetAdvVCode = D.cRetAdvVCode

--采购退货申请单
update VReturnApplyH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from VReturnApplyH H INNER JOIN (SELECT cRetApplyVCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM VReturnApplyDS GROUP BY cRetApplyVCode) D ON H.cRetApplyVCode = D.cRetApplyVCode

--仓库调入单
update WMoveInH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from WMoveInH H INNER JOIN (SELECT cMoveInCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM WMoveInDS GROUP BY cMoveInCode) D ON H.cMoveInCode = D.cMoveInCode

--仓库调出单
update WMoveOutH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from WMoveOutH H INNER JOIN (SELECT cMoveOutCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM WMoveOutDS GROUP BY cMoveOutCode) D ON H.cMoveOutCode = D.cMoveOutCode

--仓库调出通知单
update WMoveOutAdviceH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from WMoveOutAdviceH H INNER JOIN (SELECT cMoveOutAdvCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM WMoveOutAdviceDS GROUP BY cMoveOutAdvCode) D ON H.cMoveOutAdvCode = D.cMoveOutAdvCode

--打样完工单
update SReceiptH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from SReceiptH H INNER JOIN (SELECT cSReceiptCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM SReceiptDS GROUP BY cSReceiptCode) D ON H.cSReceiptCode = D.cSReceiptCode

--打样返工单
update SVReturnH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from SVReturnH H INNER JOIN (SELECT cSVReturnCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM SVReturnDS GROUP BY cSVReturnCode) D ON H.cSVReturnCode = D.cSVReturnCode

--样板出货单
update SDeliveryH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from SDeliveryH H INNER JOIN (SELECT cSDeliveryCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM SDeliveryDS GROUP BY cSDeliveryCode) D ON H.cSDeliveryCode = D.cSDeliveryCode

--样板收退货单
update SReturnInH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from SReturnInH H INNER JOIN (SELECT cSReturnInCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM SReturnInDS GROUP BY cSReturnInCode) D ON H.cSReturnInCode = D.cSReturnInCode

--样板库存调整单
update SProfitLossH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from SProfitLossH H INNER JOIN (SELECT cSProfitLossCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM SProfitLossDS GROUP BY cSProfitLossCode) D ON H.cSProfitLossCode = D.cSProfitLossCode

--样板盘点单
update SCheckH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from SCheckH H INNER JOIN (SELECT cSCheckCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM SCheckDS GROUP BY cSCheckCode) D ON H.cSCheckCode = D.cSCheckCode


--零售单
update RetailCH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney, fDisMoney = D.fDisMoney
from RetailCH H INNER JOIN (SELECT cRetailCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney, SUM(iQuantity * fDisPrice) AS fDisMoney FROM RetailCDS GROUP BY cRetailCode) D ON H.cRetailCode = D.cRetailCode

--应收款调整单
update PayInAdjustH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from PayInAdjustH H INNER JOIN (SELECT cPayInAdjustCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM PayInAdjustDS GROUP BY cPayInAdjustCode) D ON H.cPayInAdjustCode = D.cPayInAdjustCode

--应付款调整单
update PayOutAdjustH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from PayOutAdjustH H INNER JOIN (SELECT cPayOutAdjustCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM PayOutAdjustDS GROUP BY cPayOutAdjustCode) D ON H.cPayOutAdjustCode = D.cPayOutAdjustCode

--应付款调整单
update VIPIntegralGiftH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from VIPIntegralGiftH H INNER JOIN (SELECT cVIPIntegralGiftCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM VIPIntegralGiftDS GROUP BY cVIPIntegralGiftCode) D ON H.cVIPIntegralGiftCode = D.cVIPIntegralGiftCode

--网上订货单
update WebOrderH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from WebOrderH H INNER JOIN (SELECT cWebOrderCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM WebOrderDS GROUP BY cWebOrderCode) D ON H.cWebOrderCode = D.cWebOrderCode

--备货单
update StockupH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from StockupH H INNER JOIN (SELECT cStockupCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM StockupDS GROUP BY cStockupCode) D ON H.cStockupCode = D.cStockupCode

--采购申请单
update PurchaseApplyH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from PurchaseApplyH H INNER JOIN (SELECT cPurApplyCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM PurchaseApplyDS GROUP BY cPurApplyCode) D ON H.cPurApplyCode = D.cPurApplyCode

--网销订单
update EOrderH
set iQuantity = D.iQuantity, fCardMoney = D.fCardMoney, fStdMoney = D.fStdMoney, fPasMoney = D.fPasMoney, fBalMoney = D.fBalMoney, fCostMoney = D.fCostMoney
from EOrderH H INNER JOIN (SELECT cEOrderCode, SUM(iQuantity) AS iQuantity, SUM(iQuantity * fCardPrice) AS fCardMoney, SUM(iQuantity * fStdPrice) AS fStdMoney, SUM(iQuantity * fPasPrice) AS fPasMoney, SUM(iQuantity * fBalPrice) AS fBalMoney, SUM(iQuantity * fCostPrice) AS fCostMoney FROM EOrderDS GROUP BY cEOrderCode) D ON H.cEOrderCode = D.cEOrderCode

--生产单
update MProduceH
set iQuantity = D.iQuantity
from MProduceH H INNER JOIN (SELECT cMProduceCode, SUM(iQuantity) AS iQuantity FROM MProduceD GROUP BY cMProduceCode) D ON H.cMProduceCode = D.cMProduceCode