MERGE DestinationTable AS D
USING @SourceTable AS S
ON D.Alternate_ID = S._ID
WHEN MATCHED AND
(
D.Candidate_ID <> S.Candidate_ID OR ISNULL(D.Vacancy_ID,'') <> S.Vacancy_ID
)
THEN
UPDATE SET
D.FName = S.FName,
D.Department = S.Department,
WHEN NOT MATCHED BY TARGET
THEN INSERT
(
Alternate_ID,
FName,
Department
)
VALUES
(
S.ID,
S.FName,
S.Department
)
WHEN NOT MATCHED BY SOURCE
--How to add a where clause to the delete statement here
THEN DELETE; --E.g WHERE D.Department <> 'HR'
如果它们已从源中删除,我正在使用上面的 Merge 语句删除 DestinationTable 中的记录
有谁知道如何在 Delete 语句中添加 WHERE 条件?我只想从 ColA 等于特定常量字符串的目标中删除。