change detection via EXCEPT
fmms opened this issue · comments
Felix Möller commented
Hi,
instead of the NULLIF which can quiet unreadable I prefer using the EXCEPT version of change detection. It would be great if this tool could do that as well. They are described at http://www.made2mentor.com/2013/05/writing-t-sql-merge-statements-the-right-way/ .
MERGE #Customer_New AS Target
USING #Customer_Orig AS Source
ON Target.CustomerNum = Source.CustomerNum
WHEN MATCHED AND EXISTS
(SELECT Source.CustomerName, Source.Planet
EXCEPT
SELECT Target.CustomerName, Target.Planet)
THEN
UPDATE SET
Target.CustomerName = Source.CustomerName
,Target.Planet = Source.Planet
WHEN NOT MATCHED BY TARGET
THEN
INSERT (CustomerNum, CustomerName, Planet)
VALUES (CustomerNum, Source.CustomerName, Source.Planet)
WHEN NOT MATCHED BY SOURCE THEN DELETE;
Daniel Nolan commented
There's now a pull request for this issue: #106
Will complete it within a week or so if there's no issues reported.