I have three tables tb1,tb2 and tbTotal. They have the same schemas. What I want is to merge tb1 with tbTotal. I have done this and it works fines. My script:;with cte as (select skey=@skey,col1=@col1,col2=@col2,col3=@col3)merge tbTotal dusing cte son s.skey = d.skeywhen matched then updateset col1=s.col1 ,...when not matched by target then insert(skey, col1, ...)values (s.skey, s.col1,...);
Also I want to remove all records in dt2 from dtTotal. I am not sure how to modify the code.By the way, db1 and db2 can be empty.Thanks.