我正在尝试从临时表中将MERGE
导入我们的常规表。但是,SQL Server Management Studio在ZipCodeTerritory
语句中的UPDATE
表名称上显示错误。
我之前没有写过MERGE
,但我无法看到下面的语法有什么问题。由于智能感知错误报告可能与Management Studio非常具有描述性,因此其他任何人都可以看到下面的查询有什么问题吗?
MERGE INTO ZipCodeTerritory as Target
USING ZipCodeTerritoryTemp as Source
ON
Target.Id = Source.Id
WHEN MATCHED THEN
UPDATE ZipCodeTerritory SET Target.ChannelCode = Source.ChannelCode, Target.DrmTerrDesc = Source.DrmTerrDesc, Target.IndDistrnId = Source.IndDistrnId,
Target.StateCode = Source.StateCode, Target.ZipCode = Source.ZipCode, Target.EndDate = Source.EndDate, Target.EffectiveDate = Source.EffectiveDate,
Target.LastUpdateId = Source.LastUpdateId, Target.LastUpdateDate = Source.LastUpdateDate, Target.ErrorCodes = Source.ErrorCodes,
Target.Status = Source.Status
WHERE Target.Id = Source.Id
WHEN NOT MATCHED THEN
INSERT INTO ZipCodeTerritory (ChannelCode, DrmTerrDesc, IndDistrnId, StateCode, ZipCode, EndDate, EffectiveDate, LastUpdateId, LastUpdateDate, ErrorCodes, Status)
VALUES(Source.ChannelCode, Source.DrmTerrDesc, Source.IndDistrnId, Source.StateCode, Source.ZipCode, Source.EndDate, Source.EffectiveDate, Source.LastUpdateId, Source.LastUpdateDate, Source.ErrorCodes, Source.Status)
答案 0 :(得分:2)
Check syntax,Update
和Insert
子句没有表名。它也不是Merge Into
简单Merge
。
MERGE ZipCodeTerritory as Target
...
WHEN MATCHED THEN
UPDATE SET Target.ChannelCode = Source.ChannelCode ...
WHEN NOT MATCHED THEN
INSERT (Ch ...
为什么呢?表名是多余的,因为它在Merge
子句中被告知。