我正在尝试使用合并从链接服务器插入记录。该表只有两列,需要使用它们才能检查新记录。
MERGE dbo.[TableA] AS Target
USING (SELECT [PERMNUM], [ABS_DATE]
FROM [Linked Server].[dbo].[TableA])
AS source ([PERMNUM], [ABS_DATE]
ON (Target.[PERMNUM] = source.[PERMNUM]
AND Target.[ABS_DATE] = source.[ABS_DATE])
WHEN NOT MATCHED THEN
INSERT ([PERMNUM], [ABS_DATE])
VALUES (source.[PERMNUM], source.[ABS_DATE]);
我收到以下错误。
Msg 156, Level 15, State 1, Line 6
Incorrect syntax near the keyword 'ON'.
如何在ON子句中使用这两列?我看了其他的例子,据我所知,我说得对。
答案 0 :(得分:3)
看起来好像我失踪了')'
我修复了代码,现在它是正确的:
SET NOCOUNT ON
MERGE dbo.[PSPI_DAY_ABSENCES] AS Target
USING (SELECT [PERMNUM], [ABS_DATE]
FROM [SQLPASS01].[PSPI].[dbo].[PSPI_DAY_ABSENCES])
AS source ([PERMNUM], [ABS_DATE])
ON Target.[PERMNUM] = source.[PERMNUM] AND Target.[ABS_DATE] = source.[ABS_DATE]
WHEN NOT MATCHED THEN
INSERT ([PERMNUM], [ABS_DATE])
VALUES (source.[PERMNUM], source.[ABS_DATE]);