Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DECLARE @StartVersionID BIGINT, @EndVersionID BIGINT
-- Set the starting version ID
SET @StartVersionID = (
SELECT Change_Tracking_Version
FROM etl.Change_Tracking_Version
WHERE Table_Name = 'Emp')
-- Set the ending version ID
SET @EndVersionID = CHANGE_TRACKING_CURRENT_VERSION() -- Set the ending version ID
SELECT ct.ID
, e.FirstName
, e.MiddleName
, e.LastName
, ct.SYS_CHANGE_OPERATION [Operation]
FROM CHANGETABLE(CHANGES dbo.Emp, @StartVersionID) ct
LEFT JOIN dbo.Emp e
ON e.ID = ct.ID
WHERE (SELECT MAX(v)
FROM (VALUES(ct.SYS_CHANGE_VERSION), (ct.SYS_CHANGE_CREATION_VERSION)) AS VALUE(v)) <= @EndVersionID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.