Blog Pages

Merge with two options for MATCHED case

Remainder for MERGE syntax:

If there are 2 options what to do when we have a MATCHED between the source and he target tables - most of the times it will be deletion and update - we can do that like this:

MERGE <target_table> [AS TARGET]
.....
WHEN MATCHED AND <condition>
THEN DELETE
WHEN MATCHED  -- all the other cases of MATCHED other then the condition above
THEN UPDATE 
SET ColumnA = s.SomeValue
.....