应收/付单表头金额和表体金额汇总不一致修复SQL参考原创
91人赞赏了该文章
368次浏览
编辑于2024年10月12日 11:43:42
业务场景:某些异常情况下,应收/付单表头金额和表体金额汇总不一致,需要数据库修复
注意:由于单据头金额会在期间结账时计入余额表,并影响下期期初余额,所以如果有修改到已结账期间的单据的单据头金额,应收/付款模块都需要反结账至涉及的最早期间重新结账回来,避免应收/付款汇总表/明细表查询余额异常。(单独反应收/付款模块即可)
如下SQL语句仅供参考!!!更新前建议做全表备份!!!
应收单:
SELECT A.FBILLNO 单据编号,A.FID,A.FDATE 业务日期,A.FSETTLEORGID 结算组织,A.FCUSTOMERID 客户,A.FCURRENCYID 币别,B.FMAINBOOKSTDCURRID 本位币, A.FALLAMOUNTFOR 头价税合计,(SELECT SUM(FALLAMOUNTFOR) FROM T_AR_RECEIVABLEENTRY WHERE FID=A.FID) 体价税合计, B.FALLAMOUNT 头价税合计本位币,(SELECT SUM(FALLAMOUNT) FROM T_AR_RECEIVABLEENTRY WHERE FID=A.FID) 体价税合计本位币, B.FNOTAXAMOUNTFOR 头不含税金额,(SELECT SUM(FNOTAXAMOUNTFOR) FROM T_AR_RECEIVABLEENTRY WHERE FID=A.FID) 体不含税金额, B.FNOTAXAMOUNT 头不含税金额本位币,(SELECT SUM(FNOTAXAMOUNT) FROM T_AR_RECEIVABLEENTRY WHERE FID=A.FID) 体不含税金额本位币, B.FTAXAMOUNTFOR 头税额,(SELECT SUM(FTAXAMOUNTFOR) FROM T_AR_RECEIVABLEENTRY WHERE FID=A.FID) 体税额, B.FTAXAMOUNT 头税额本位币,(SELECT SUM(FTAXAMOUNT) FROM T_AR_RECEIVABLEENTRY WHERE FID=A.FID) 体税额本位币 --UPDATE B SET FALLAMOUNT=(SELECT SUM(FALLAMOUNT) FROM T_AR_RECEIVABLEENTRY WHERE FID=A.FID),FNOTAXAMOUNTFOR=(SELECT SUM(FNOTAXAMOUNTFOR) FROM T_AR_RECEIVABLEENTRY WHERE FID=A.FID),FNOTAXAMOUNT=(SELECT SUM(FNOTAXAMOUNT) FROM T_AR_RECEIVABLEENTRY WHERE FID=A.FID),FTAXAMOUNTFOR=(SELECT SUM(FTAXAMOUNTFOR) FROM T_AR_RECEIVABLEENTRY WHERE FID=A.FID),FTAXAMOUNT=(SELECT SUM(FTAXAMOUNT) FROM T_AR_RECEIVABLEENTRY WHERE FID=A.FID) --UPDATE A SET A.FALLAMOUNTFOR=(SELECT SUM(FALLAMOUNTFOR) FROM T_AR_RECEIVABLEENTRY WHERE FID=A.FID) from T_AR_RECEIVABLE A --单据头 left join T_AR_RECEIVABLEFIN b on a.fid=b.fid --单据头财务信息 where a.fbillno='单据编号' and (b.FALLAMOUNT<>(select sum(FALLAMOUNT) from T_AR_RECEIVABLEENTRY where fid=a.fid) or b.FNOTAXAMOUNTFOR<>(select sum(FNOTAXAMOUNTFOR) from T_AR_RECEIVABLEENTRY where fid=a.fid) or b.FTAXAMOUNTFOR<>(select sum(FTAXAMOUNTFOR) from T_AR_RECEIVABLEENTRY where fid=a.fid) or b.FNOTAXAMOUNT<>(select sum(FNOTAXAMOUNT) from T_AR_RECEIVABLEENTRY where fid=a.fid) or b.FTAXAMOUNT<>(select sum(FTAXAMOUNT) from T_AR_RECEIVABLEENTRY where fid=a.fid) or A.FALLAMOUNTFOR<>(SELECT SUM(FALLAMOUNTFOR) FROM T_AR_RECEIVABLEENTRY WHERE FID=A.FID))
应付单:
SELECT A.FBILLNO 单据编号,A.FID,A.FDATE 业务日期,A.FSETTLEORGID 结算组织,A.FSUPPLIERID 供应商,A.FCURRENCYID 币别,B.FMAINBOOKSTDCURRID 本位币, A.FALLAMOUNTFOR 头价税合计,(SELECT SUM(FALLAMOUNTFOR) FROM T_AP_PAYABLEENTRY WHERE FID=A.FID) 体价税合计, B.FALLAMOUNT 头价税合计本位币,(SELECT SUM(FALLAMOUNT) FROM T_AP_PAYABLEENTRY WHERE FID=A.FID) 体价税合计本位币, B.FNOTAXAMOUNTFOR 头不含税金额,(SELECT SUM(FNOTAXAMOUNTFOR) FROM T_AP_PAYABLEENTRY WHERE FID=A.FID) 体不含税金额, B.FNOTAXAMOUNT 头不含税金额本位币,(SELECT SUM(FNOTAXAMOUNT) FROM T_AP_PAYABLEENTRY WHERE FID=A.FID) 体不含税金额本位币, B.FTAXAMOUNTFOR 头税额,(SELECT SUM(FTAXAMOUNTFOR) FROM T_AP_PAYABLEENTRY WHERE FID=A.FID) 体税额, B.FTAXAMOUNT 头税额本位币,(SELECT SUM(FTAXAMOUNT) FROM T_AP_PAYABLEENTRY WHERE FID=A.FID) 体税额本位币 --UPDATE B SET FALLAMOUNT=(SELECT SUM(FALLAMOUNT) FROM T_AP_PAYABLEENTRY WHERE FID=A.FID),FNOTAXAMOUNTFOR=(SELECT SUM(FNOTAXAMOUNTFOR) FROM T_AP_PAYABLEENTRY WHERE FID=A.FID),FNOTAXAMOUNT=(SELECT SUM(FNOTAXAMOUNT) FROM T_AP_PAYABLEENTRY WHERE FID=A.FID),FTAXAMOUNTFOR=(SELECT SUM(FTAXAMOUNTFOR) FROM T_AP_PAYABLEENTRY WHERE FID=A.FID),FTAXAMOUNT=(SELECT SUM(FTAXAMOUNT) FROM T_AP_PAYABLEENTRY WHERE FID=A.FID) --UPDATE A SET A.FALLAMOUNTFOR=(SELECT SUM(FALLAMOUNTFOR) FROM T_AP_PAYABLEENTRY WHERE FID=A.FID) from T_AP_PAYABLE A --单据头 left join T_AP_PAYABLEFIN b on a.fid=b.fid --单据头财务信息 where a.fbillno='单据编号' and (b.FALLAMOUNT<>(select sum(FALLAMOUNT) from T_AP_PAYABLEENTRY where fid=a.fid) or b.FNOTAXAMOUNTFOR<>(select sum(FNOTAXAMOUNTFOR) from T_AP_PAYABLEENTRY where fid=a.fid) or b.FTAXAMOUNTFOR<>(select sum(FTAXAMOUNTFOR) from T_AP_PAYABLEENTRY where fid=a.fid) or b.FNOTAXAMOUNT<>(select sum(FNOTAXAMOUNT) from T_AP_PAYABLEENTRY where fid=a.fid) or b.FTAXAMOUNT<>(select sum(FTAXAMOUNT) from T_AP_PAYABLEENTRY where fid=a.fid) OR A.FALLAMOUNTFOR<>(SELECT SUM(FALLAMOUNTFOR) FROM T_AP_PAYABLEENTRY WHERE FID=A.FID))
赞 91
91人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
1人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读