简体   繁体   English

合并中无法绑定多部分标识符

[英]The multi-part identifier could not be bound in merge

I am using below merge and getting "The multi-part identifier "MasterSource.monthvrip" could not be bound" error.我正在使用下面的合并并收到“无法绑定多部分标识符“MasterSource.monthvrip””错误。 Checked a lot in internet but no luck .在互联网上查了很多,但没有运气。 Looks like using some defined keyword but not able to figure out.看起来像使用了一些定义的关键字,但无法弄清楚。 Any suggestion will be helpful.任何建议都会有所帮助。

USE TestDatabase

MERGE [dbo].[cost1] AS target   
USING (     
  SELECT [monthvrip]
  FROM [dbo].[cost]
) AS MasterSource
ON (MasterSource.[monthvrip] = target.[monthvrip])

WHEN MATCHED AND (MasterSource.[monthvrip] <> target.[monthvrip])
THEN UPDATE 
  SET MasterSource.[monthvrip] = target.[monthvrip]

WHEN NOT MATCHED BY target THEN 
INSERT 
  ([monthvrip])
VALUES 
  (MasterSource.[monthvrip])

OUTPUT
$action,
inserted.*,
deleted.*;

Msg 4104, Level 16, State 1, Line 4消息 4104,级别 16,状态 1,第 4 行

The multi-part identifier "MasterSource.monthvrip" could not be bound.无法绑定多部分标识符“MasterSource.monthvrip”。

You need to change你需要改变

THEN UPDATE 
  SET MasterSource.[monthvrip] = target.[monthvrip]

to

THEN UPDATE 
  SET target.[monthvrip] = MasterSource.[monthvrip]

The way you have it at the moment, you're trying to update the source of the merge, rather than the target.就您目前的情况而言,您正在尝试更新合并的源,而不是目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM