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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-12-13 : 08:23:13
|
| Wayne writes "Currently I use a cursor to loop thru all the records in the temp table, I only insert record if it does not already exist in the live table. Is there a more efficient way of doing this? (like without using the cursor)" |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-12-13 : 08:36:43
|
| insert tblselect tmp.*from #temp tmpleft join tblon tmp.pk = tbl.pkwhere tbl.pk is nullYou might need a distinct too.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
dsdeming
479 Posts |
Posted - 2004-12-13 : 08:38:07
|
| Try checking for nulls from an outer join, something like this:insert into tablea( col1, col2... )select b.col1, b.col2...from tableb b left join tablea a on b.key = a.keywhere a.key is nullDennis |
 |
|
|
|
|
|