Skip to content

Instantly share code, notes, and snippets.

@earino
Created September 17, 2015 19:55
Show Gist options
  • Select an option

  • Save earino/fb259896cdffb060a6c3 to your computer and use it in GitHub Desktop.

Select an option

Save earino/fb259896cdffb060a6c3 to your computer and use it in GitHub Desktop.
merge example
MERGE INTO Inventory AS I
USING Changes AS C
ON I.Part = C.Part
WHEN MATCHED AND
I.Action = 'Mod'
THEN UPDATE
SET Qty = I.Qty + C.Qty
WHEN NOT MATCHED AND
I.Action = 'New'
THEN INSERT (Part, Qty)
VALUES (C.Part, C.Qty)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment