有部分计量单位保存出错。
MERGE 语句试图多次更新或删除同一行。目标行与多个源行匹配时会出现这种情况。MERGE 语句无法多次更新/删除目标表的同一行。请简化 ON 子句,以确保目标行最多与一个源行匹配,也可以使用 GROUP BY 子句对源行分组。
发生时间: 2018-01-16 03:05:18
错误编号: BOS_ExecuteNonQuery
错误信息: MERGE 语句试图多次更新或删除同一行。目标行与多个源行匹配时会出现这种情况。MERGE 语句无法多次更新/删除目标表的同一行。请简化 ON 子句,以确保目标行最多与一个源行匹配,也可以使用 GROUP BY 子句对源行分组。
Sql语句: merge into T_BD_MATERIALPRODUCE u1 using(SELECT UM.FMATERIALID, CASE WHEN T4.FUNITGROUPID = T6.FUNITGROUPID THEN CAST((BD1.FCONVERTNUMERATOR * BD2.FCONVERTDENOMINATOR) AS NUMERIC(23, 10)) ELSE ISNULL(CAST((CAST((CAST((BD1.FCONVERTNUMERATOR * T8.FCONVERTNUMERATOR) AS NUMERIC(23, 10)) * BD2.FCONVERTDENOMINATOR) AS NUMERIC(23, 10)) * T9.FCONVERTDENOMINATOR) AS NUMERIC(23, 10)), -1.0) END num, CASE WHEN T4.FUNITGROUPID = T6.FUNITGROUPID THEN CAST((BD1.FCONVERTDENOMINATOR * BD2.FCONVERTNUMERATOR) AS NUMERIC(23, 10)) ELSE ISNULL(CAST((CAST((CAST((BD1.FCONVERTDENOMINATOR * T8.FCONVERTDENOMINATOR) AS NUMERIC(23, 10)) * BD2.FCONVERTNUMERATOR) AS NUMERIC(23, 10)) * T9.FCONVERTNUMERATOR) AS NUMERIC(23, 10)), -1.0) END nom FROM (SELECT TB.FMATERIALID, TB.FBASEUNITID, TP.FPRODUCEUNITID FROM T_BD_MATERIALBASE TB INNER JOIN T_BD_MATERIAL TM ON TB.FMATERIALID = TM.FMATERIALID INNER JOIN T_BD_MATERIALPRODUCE TP ON TB.FMATERIALID = TP.FMATERIALID INNER JOIN @FUNITID_udt1 TU ON TU.FID = TP.FPRODUCEUNITID) um LEFT OUTER JOIN T_BD_MATERIAL TM ON UM.FMATERIALID = TM.FMaterialId LEFT OUTER JOIN T_BD_MATERIALBASE TB ON UM.FMATERIALID = TB.FMaterialId LEFT OUTER JOIN T_BD_UNIT T2 ON UM.FPRODUCEUNITID = T2.FUNITID LEFT OUTER JOIN T_BD_UNIT T3 ON UM.FBASEUNITID = T3.FUNITID LEFT OUTER JOIN T_BD_UNITGROUP T4 ON T4.FUNITGROUPID = T2.FUNITGROUPID LEFT OUTER JOIN T_BD_UNIT T5 ON (T4.FUNITGROUPID = T5.FUNITGROUPID AND T5.FISBASEUNIT = '1') LEFT OUTER JOIN T_BD_UNITCONVERTRATE BD1 ON ((BD1.FCURRENTUNITID = UM.FPRODUCEUNITID AND BD1.FDESTUNITID = T5.FUNITID) AND BD1.FMASTERID = 0) LEFT OUTER JOIN T_BD_UNITGROUP T6 ON T6.FUNITGROUPID = T3.FUNITGROUPID LEFT OUTER JOIN T_BD_UNIT T7 ON (T6.FUNITGROUPID = T7.FUNITGROUPID AND T7.FISBASEUNIT = '1') LEFT OUTER JOIN T_BD_UNITCONVERTRATE BD2 ON ((UM.FBASEUNITID = BD2.FCURRENTUNITID AND T7.FUNITID = BD2.FDESTUNITID) AND BD2.FMASTERID = 0) LEFT OUTER JOIN T_BD_UNITCONVERTRATE T8 ON ((T5.FUNITID = T8.FCURRENTUNITID AND TB.FBASEUNITID = T8.FDESTUNITID) AND (T8.FMASTERID = TM.FMASTERID OR T8.FMASTERID = 0)) LEFT OUTER JOIN T_BD_UNITCONVERTRATE T9 ON ((T7.FUNITID = T9.FCURRENTUNITID AND TB.FBASEUNITID = T9.FDESTUNITID) AND (T9.FMASTERID = TM.FMASTERID OR T9.FMASTERID = 0))) u2 on (u1.FMATERIALID = u2.FMATERIALID) when matched then update set u1.FPRDURNUM=u2.NUM,u1.FPRDURNOM=u2.NOM;
推荐阅读