September 29, 2016 at 9:53 am
Does this help? The code is based on your sample data above, which by the way, has syntax errors I will leave for you to find and correct.
print 'Display data in Main that exists in Temp';
select
*
from
dbo.Main m
where
exists(select 1 from dbo.Temp t where t.ContactID = m.ContactID)
print 'Delete the data in Main that exists in Temp';
with base as (
select
*
from
dbo.Main m
where
exists(select 1 from dbo.Temp t where t.ContactID = m.ContactID)
)
delete from base;
print 'Display data in Main that exists in Temp, should not be any now.';
select
*
from
dbo.Main m
where
exists(select 1 from dbo.Temp t where t.ContactID = m.ContactID)
print 'Insert data from Temp into Main';
insert into dbo.Main(ContactID, FirstName, MiddleName, LastName)
select ContactID, FirstName, MiddleName, LastName
from dbo.Temp;
print 'Show data in Main.';
select * from dbo.Main;
Viewing post 1 (of 2 total)
You must be logged in to reply to this topic. Login to reply