Another alternative
insert y values (col1, col2, col3)
select col1, col2, col3 from x
left join x.yourkeycolumn = y.yourkeycolumn
where y.yourkeycolumn is null
I have rows in two tables, say X and Y. X is the source, Y is the destination. I need to take certain rows from X and insert them into Y. Some of these rows already exist in Y, some are new rows. I have a SELECT statement to identify the source rows from X. I need to leave table Y untouched except for the rows that will be added or overwritten by the rows from X
How do I take certain rows from X and insert them into Y?
I'm running SQL Server 2005.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Try these as well:
insert into y
select *
from x
where key not in(select y.key from y where x.key = y.key );
insert into y
select *
from x
where key not in(select key from y);
insert into y
select x.*
from x join y on x.key != y.key;
insert y values (col1, col2, col3)
select col1, col2, col3 from x
left join y on x.yourkeycolumn = y.yourkeycolumn
where y.yourkeycolumn is null;
Business Accounts
Answer for Membership
by: aneeshattingalPosted on 2009-08-30 at 16:52:03ID: 25219893
Hello pixelchef,
insert into y
select *
from x
where not exists (select 1 from y where x.key = y.key )
Regards,
Aneesh