November 27, 2008 at 11:48 am
Hello!
I have that compare 2 tables (table1 and table2), if tne rows of the table1 dont exist in table2, have to inserted then in table2 , but if there are rows en table2 that no exist in table1 its have to deleted.
Can you help me pls!
November 27, 2008 at 12:36 pm
diehc (11/27/2008)
Hello!I have that compare 2 tables (table1 and table2), if tne rows of the table1 dont exist in table2, have to inserted then in table2 , but if there are rows en table2 that no exist in table1 its have to deleted.
Can you help me pls!
Assuming that both tables have the exact same structure (columns, data types, etc):
;with InsertValues as (
select
*
from
dbo.table1
except
select
*
from
dbo.table2
)
insert into dbo.table2
select
*
from
InsertValues;
with DeleteValues as
(
select
*
from
dbo.table2
except
select
*
from
dbo.table1
)
delete from dbo.table2
from
dbo.table2 t2
inner join DeleteValues dv
on (t2.keycolumn = dv.keycolumn);
Can't give you much more as you haven't provided enough information to tell you more.
Please read the article below regarding asking for help. Follow the guidelines given and you will get much better answers to your questions.
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply