Using 2 tables I need to delete distinct, and insert new records.
I've table1 and table2. First 3 records are the same in both tables, but last 2 records are different. So first of all I need to delete different records and after that add new records.
I use SQL Server 2005, so MERGE function doesn't exist yet. How could I resolve this without using MERGE?
Thank you very much!
create table #Table1 (F1 char(5),F2 char(5),F3 char(5))
insert into #Table1
select 'AAA','BBB','CCC' union all
select 'AAA','BBB','CCC' union all
select 'AAA','BBB','CCC' union all
select 'AAA','BBB','DDD' union all
select 'AAA','BBB','EEE'
SELECT * FROM #Table1
create table #Table2 (F1 char(5), F2 char(5), F3 char(5))
insert into #Table2
select 'AAA','BBB','CCC' union all
select 'AAA','BBB','CCC' union all
select 'AAA','BBB','CCC' union all
select 'AAA','BBB','FFF' union all
select 'AAA','BBB','GGG'
SELECT * FROM #Table2
Aucun commentaire:
Enregistrer un commentaire