Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

transfer rows from table A to table B that only if they are not in B? 1

Status
Not open for further replies.

joelwenzel

Programmer
Jun 28, 2002
448
I want to create a DTS package that transfers data from table A to table B. However, table B might already have data from table A in it. I only want unique values in table B (and A).

So, is there some way to only copy over records from table A that are not already present in table B
 
oh yeah, I tried that but there is one additional condition, Table B is in a different database which is potentially on a different machine. If it is on the same machine, I think I could use something like

DBName.dbo.tableb
 
Correct, if it's in a different database you need to use the three part name.

If it is on a different server setup a linked server from your box to the remote SQL Server then use the four part name to pull the data.

Code:
select *
from tablea
where tablea.id not in (select id from ServerName.DBName.dbo.tableb)

Denny
MCSA (2003) / MCDBA (SQL 2000)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
Donate to Katrina relief
 
oh cool. I didn't know about the four part name. Thanks a lot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top