需要从源表中删除所有行,然后
仅当目标表中尚不存在已删除的行时,才将已删除的行插入目标表。
是否可以使用单个 sql 发出问题?
代码是我迄今为止尝试过的代码(尽管有错误)。谢谢你!
create table #Target (column01 varchar(100)
,employee_number varchar(10)
)
Insert into #Target (column01, employee_number)
values ('2','222')
create table #Srs (column01 varchar(100)
,employee_number varchar(10)
)
Insert into #Srs (column01, employee_number)
values ('1','111')
,('2','222')
,('3','333')
,('4','444')
;with cteTable as (Select column01, employee_number from #Srs)
insert into #Target (column01, employee_number)
select * from (Delete from cteTable output deleted.column01, deleted.employee_number) t
where not exists (select 1
from #Target t1
where t1.employee_number = t.employee_number)
不应将 2,'222' 插入 #Target on call to ";with cteTable.."