On a SQL MERGE
how do I insert a "do nothing" type statement? For example, I have this right now:
MERGE INTO dbo.Worker AS T
USING dbo.Collector_Worker AS S
ON T.WWID = S.WWID
WHEN MATCHED THEN UPDATE SET
T.IDSID = S.IDSID,
...
WHEN NOT MATCHED THEN
INSERT (WWID, IDSID, ...)
VALUES (S.WWID, S.IDSID, ...)
WHEN NOT MATCHED BY SOURCE THEN
UPDATE SET T.Person_Status_Type = 'INACTIVE', T.Active = 0;
There are a ton of other columns where the ...
characters are. So this works great except for the fact that it updates every row that already exists, even if there are no changes. As the table has a million rows in it, that's a ton of unnecessary modifications. I only want to update the row if a change was made.
If I try and just add an AND T.IDSID <> S.IDSID
to the ON
statement then it'll fail because it now tries to run the INSERT
statement.