执行存储过程时,MERGE语句尝试更新或删除错误

时间:2015-10-15 17:15:54

标签: sql sql-server tsql stored-procedures

尝试使用MERGE时收到以下错误消息:

  

MMC.SOT_Load包未能执行,在步骤3停止 - 步骤名称“SOT”   代码:0xC002F210源:Yellow_Fields执行SQL任务描述:执行查询“DECLARE @RC int - TODO:设置参数值he ...”失败,并显示以下错误:“MERGE语句尝试更新或删除同一行更多当目标行匹配多个源行时会发生这种情况.MERGE语句不能多次UPDATE / DELETE目标表的同一行。优化ON子句以确保目标行最多匹配一个源行,或者使用GROUP BY子句对源行进行分组。“可能的故障原因:查询问题,“ResultSet”属性设置不正确,参数设置不正确或连接未正确建立。

这是我正在使用的SQL:

MERGE   MasterTable     As Target
USING   AcademicAffairs As Source
ON      (Target.Life_Hosp = Source.Life_Hosp) 
AND     (Source.IsValid = 1) 
AND     (Target.IsValid = 1) 
AND     (Target.Life_Hosp is not Null And LEN(Target.Life_Hosp) > 0)
WHEN Matched Then Update 
    Set Target.DEA = COALESCE(NullIf(LTrim(RTrim(Source.DEA)),''), Target.DEA),
    --Target.DPF = COALESCE(NullIf(LTrim(RTrim(Source.DPF)),''),Target.DPF),
    Target.LastName = COALESCE(NullIf(LTrim(RTrim(Source.LastName)),''),Target.LastName),
    Target.FirstName = COALESCE(NullIf(LTrim(RTrim(Source.FirstName)),''),Target.FirstName),
    Target.License_Type = COALESCE(NullIf(LTrim(RTrim(Source.License_Type)),''),Target.License_Type)
;

0 个答案:

没有答案