Hi All,
If I have two tables in souce DB syncing to one table in target DB, how do I use SQL 2008 change tracking feature to track it?
The following is an example that we use for one table to one table sync.
DECLARE @last_sync_version bigint;
SET @last_sync_version = <value obtained from query>;
SELECT e.ID, e.SSN, e.FirstName, e.LastName,
c.SYS_CHANGE_VERSION, c.SYS_CHANGE_OPERATION
FROM CHANGETABLE (CHANGES Employees, @last_sync_version) AS c
LEFT OUTER JOIN Employees AS e
ON e.ID = c.ID
Now I want to sync Employees and Organizations tables in source DB to Employees table in target DB. Currently we use the following statement and key comparing method to sync
SELECT e.ID, e.SSN, e.FirstName, e.LastName, O.Name
FROM Employees e JOIN Organizations O
ON e.OrgID = O.ID
Now, if I want to use 2008 change tracking feature, what the select statement should look like? Would the following statement work and be reliable?
SELECT e.ID, e.SSN, e.FirstName, e.LastName, O.Name
FROM Employees e JOIN Organizations O
ON e.OrgID = O.ID
RIGHT JOIN CHANGETABLE (CHANGES Employees, @last_sync_version) AS c
ON e.ID = c.ID
RIGHT JOIN CHANGETABLE (CHANGES Organizations, @last_sync_version) AS c2
ON O.ID = c2.ID
Thank you for your time!