-- I use a table to log the start and finish time, package name, number of rows inserted and number of rows updatedinsert into SSIS_Log (PackageName,DTStart) values (?,GetDate()); -- Map the System variable "PackageName"declare @mergeResultsTable table (MergeAction VARCHAR(20)); declare @insertCount int, @updateCount int;MERGE Table_A AS TARGETUSING (SELECT Col1 ,Col2 ..... ,ColNFROM Table_B) AS SOURCE ON (TARGET.Key1 = SOURCE.Key1 and TARGET.Key_2 = SOURCE.Key_2)-- UpdateWHEN MATCHED THEN UPDATE SET TARGET.Col1= SOURCE.Col1 ,TARGET.Col2= SOURCE.Col2 ,TARGET.UpdateDT=GetDate() -- I create a UpdateDT column in the target table to store the update datetime -- etc--InsertWHEN NOT MATCHED BY TARGET THEN INSERT( Col1 ,Col2 ,CreateDT -- I create a CreateDT column in the target table to store the insert (or creation) datetime -- etc)VALUES( SOURCE.Col1 ,SOURCE.Col2 ,GetDate() -- etc)OUTPUT $action into @mergeResultsTable; update SSIS_Logset UpdatedCount = -- Log the count of updated rows(SELECT COUNT(*) FROM @mergeResultsTable WHERE MergeAction = 'UPDATE'), InsertedCount = -- Log the count of inserted rows(SELECT COUNT(*) FROM @mergeResultsTable WHERE MergeAction = 'INSERT'),DTFinish = GetDate()where Idx = ( select MAX(Idx) from SSIS_Log );