A Microsoft platform for building enterprise-level data integration and data transformations solutions.
Hi @Shambhu Rai
if values match then need not insert but update the records. and also expect scenario to maintain changes like history
It seems you need a MERGE statement with OUTPUT clause, like this:
MERGE #table1 T
USING #table2 S ON T.id=S.id
WHEN MATCHED THEN
UPDATE SET value1=S.value1, value2=S.value2, value3=S.value3
WHEN NOT MATCHED BY TARGET
THEN INSERT (id,region,subregion,value1,value2,value3)
VALUES (S.id,S.region,S.subregion,S.value1,S.value2,S.value3)
OUTPUT DELETED.*, $action AS [Action], INSERTED.* ;
Refer to this article for more details: SQL Server MERGE Statement overview and examples
Best regards,
LiHong