Hi, I have a scenario where I will have to load my table incrementally using a sql query. CDC not an option and no primary key in both source query and target table. Previously I was doing truncate table and simply reload using stored procedure. I want to reduce time and resources.
I used MERGE statement and use combination of two filed in join (like T.c1 = S.c1 and T.c2 = s.C2) where C1 is binary data type and c2 is varchar. It didn't reduce my time.
Merge TargetTable As T
using
( SELECT c1,c2,c3,c4
FROM sometable
WHERE somecondition) s
on t.c1 = s.c1
and t.c2 = s.c2 ---(makes up unique condtion to check unique record)
WHEN NOT MATCHED BY TARGET THEN
insert (c1,c2,c3,c4)
values( s.c1,c2,c3,c4)
);
Note: I have c1 as varbinary and c2 as varchar. I used combination of both to identify uniquer reocord to match. This solution works but didn't reduce time of execution. I want to reduce execution time