Skip to content

Instantly share code, notes, and snippets.

@tdmitch
Created June 1, 2018 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdmitch/7a6298e40c4e42fa33a2df33a4a06a15 to your computer and use it in GitHub Desktop.
Save tdmitch/7a6298e40c4e42fa33a2df33a4a06a15 to your computer and use it in GitHub Desktop.
MERGE etl.Change_Tracking_Version AS target
USING (SELECT 'Emp' [Table_Name]
, CHANGE_TRACKING_CURRENT_VERSION() [Version_ID] — Get the change tracking version ID
) AS source
ON target.Table_Name = source.Table_Name
WHEN MATCHED — Exists? Then update
THEN UPDATE
SET target.Change_Tracking_Version = source.Version_ID
WHEN NOT MATCHED — No match? Insert
THEN INSERT (Table_Name, Change_Tracking_Version)
VALUES (source.Table_Name, source.Version_ID)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment