1
我試圖從臨時表執行MERGE
到我們的常規表中。但是,SQL Server Management Studio在UPDATE
語句中ZipCodeTerritory
表名稱上顯示錯誤。MERGE語句中的Incorret語法
我以前沒有寫過MERGE
,但是我看不出下面的語法有什麼問題。由於智能感知錯誤報告可能非常不具描述性,所以任何人都可以看到下面的查詢有什麼問題?
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)