Skip to content

Instantly share code, notes, and snippets.

@ezhov-da
Last active December 12, 2020 19:27
Show Gist options
  • Save ezhov-da/f027a44d74121fd6bf480ced793df2fd to your computer and use it in GitHub Desktop.
Save ezhov-da/f027a44d74121fd6bf480ced793df2fd to your computer and use it in GitHub Desktop.
sql mssql merge
--==> https://msdn.microsoft.com/ru-ru/library/bb510625.aspx
MERGE Production.UnitMeasure AS target
USING (SELECT @UnitMeasureCode, @Name) AS source (UnitMeasureCode, Name)
ON (target.UnitMeasureCode = source.UnitMeasureCode)
WHEN MATCHED THEN
UPDATE SET Name = source.Name
WHEN NOT MATCHED THEN
INSERT (UnitMeasureCode, Name)
VALUES (source.UnitMeasureCode, source.Name)
OUTPUT deleted.*, $action, inserted.* INTO #MyTempTable;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment