Hi @Tim Mullady ,
You can use except, please refer to the following example:
--except
create table testu1
(C1 int,C2 int)
insert into testu1 values(1,1),(2,2),(2,2),(3,3)
create table testu2
(C1 int,C2 int)
insert into testu2 values(3,3),(4,4),(1,1)
select * from testu1
select * from testu2
insert into testu2
select * from testu1 except
select * from testu2
select * from testu2
drop table testu1
drop table testu2
Output:
c1 c2
3 3
4 4
1 1
2 2
If there are duplicate rows in the newly inserted data, please refer to the following code:
create table testu1
(C1 int,C2 int)
insert into testu1 values(1,1),(2,2),(2,2),(3,3)
create table testu2
(C1 int,C2 int)
insert into testu2 values(3,3),(4,4),(1,1)
;with except_all as
(select row_number()
over(partition by C1
order by(select 0)) as rn, C1,C2
from testu1
except
select row_number()
over(partition by C1
order by(select 0)) as rn, C1,C2
from testu2)
insert into testu2
select c1,c2 from except_all
select * from testu2
drop table testu1
drop table testu2
Output:
c1 c2
3 3
4 4
1 1
2 2
2 2
If you have any question, please feel free to let me know.
Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.