销售订单新变更单生效报MERGE INTO T_PRD_MOENTRY错原创
9人赞赏了该文章
219次浏览
编辑于2024年08月05日 16:02:17
销售订单新变更单生效时,会尝试将变更后的序号更新回生产订单的需求单据行号(FSALEORDERENTRYSEQ字段),如果原来的生产订单关联的是销售订单且需求单据行号是不对的,就可能会报'MERGE INTO T_PRD_MOENTRY'错,此时可先修复脚本后再生效变更单,首先可查询出有异常的数据,脚本如下:
SELECT FENTRYID, MAX(FID) FID FROM ( SELECT DISTINCT MOE.FID, AMOE.FENTRYID, ISNULL(SOE.FSEQ, 0) FSEQ FROM T_PRD_MOENTRY_A MOEA INNER JOIN T_PRD_MOENTRY MOE ON MOEA.FENTRYID = MOE.FENTRYID LEFT OUTER JOIN T_SAL_ORDERENTRY SOE ON MOE.FSALEORDERENTRYID = SOE.FENTRYID LEFT OUTER JOIN T_PRD_MOENTRY AMOE ON MOE.FID = AMOE.FID AND MOE.FSALEORDERENTRYSEQ = AMOE.FSALEORDERENTRYSEQ WHERE MOEA.FREQSRC = '1' AND MOE.FSALEORDERENTRYID IN ( SELECT OE.FENTRYID FROM T_SAL_ORDER O INNER JOIN T_SAL_ORDERENTRY OE ON O.FID = OE.FID WHERE O.FBILLNO = 'XSDD0001' --替换成要变更的销售订单单号 ) ) T GROUP BY T.FENTRYID HAVING COUNT(T.FID) > 1
备份数据:
SELECT * INTO T_PRD_MOENTRY240426 FROM T_PRD_MOENTRY
修复数据:
MERGE INTO T_PRD_MOENTRY T USING ( SELECT MO.FBILLNO, /*MOE.FSEQ,*/ MOE.FENTRYID, MOE.FSALEORDERENTRYID, FSALEORDERNO, MOE.FSALEORDERENTRYSEQ, SOE.FSEQ FROM T_PRD_MO MO INNER JOIN T_PRD_MOENTRY MOE ON MO.FID = MOE.FID INNER JOIN T_PRD_MOENTRY_A MOEA ON MOE.FENTRYID = MOEA.FENTRYID LEFT JOIN T_SAL_ORDERENTRY SOE ON SOE.FENTRYID = MOE.FSALEORDERENTRYID WHERE MO.FID IN (123456) --第一步中查询出来的FID AND SOE.FENTRYID IS NOT NULL AND MOE.FSALEORDERENTRYSEQ <> SOE.FSEQ AND (FREQSRC = '1' OR FSRCBILLTYPE = 'SAL_SaleOrder') ) S ON (T.FENTRYID = S.FENTRYID) WHEN MATCHED THEN UPDATE SET T.FSALEORDERENTRYSEQ = S.FSEQ;
标准功能在PT-160003 [9.0.0.20240711] 发布的补丁中也会兼容这种异常数据不报错,如果是20240229版本,可打以下临时补丁:
赞 9
9人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!