Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Vassago
Starting Member
33 Posts |
Posted - 2006-03-20 : 19:53:59
|
| I have two tables that look like this:table1id contact_list_name904 ALL90905 ROLL30914 ALL30915 ALL60table2id contact_list_name905 ROLL30914 ALL30915 ALL60917 ALL90I would like append all records from table2 to table1 that don't already exist, like this:id contact_list_name904 ALL90905 ROLL30914 ALL30915 ALL60917 ALL90I have been beating myself up over how to tell if the single combination already exists on the table so sql server can ignore it and move on to the next record. Any recommendations?Vassago |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-03-20 : 19:59:05
|
use not existsdeclare @id intinsert into table1 (id)select @idwhere not exists (select * from table1 x where x.id = @id) KHChoice is an illusion, created between those with power, and those without.Concordantly, while your first question may be the most pertinent, you may or may not realize it is also the most irrelevant |
 |
|
|
Vassago
Starting Member
33 Posts |
Posted - 2006-03-20 : 20:11:21
|
| Wow, that was quick. Works perfectly! Thanks! |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-03-20 : 20:23:56
|
to insert table1 with data from table2insert into table1 (id, contact_list_name)select id, contact_list_namefrom table2 t2where not exists (select * from table1 x where x.id = t2.id) KHChoice is an illusion, created between those with power, and those without.Concordantly, while your first question may be the most pertinent, you may or may not realize it is also the most irrelevant |
 |
|
|
|
|
|
|
|