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 |
|
xdk1x
Starting Member
9 Posts |
Posted - 2004-06-17 : 04:51:36
|
| Hi!I am going through table with a cursor. Some fields of the Cursor connected table should be compared to the Primary Keys (five fields) in another table. So that I can update the second table in case that the Primary Key exists and make an insert if not so. Can you help me? If tried like this way:IF (@Var1 + @Var2) NOT IN ( SELECT PK1 + PK2 FROM table2 WHERE ((PK1 + PK2) = (PK1 + PK2))BEGIN...But it is really slow (120 rows in 16 minutes).Thanks for your help!Daniel |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2004-06-17 : 04:58:15
|
| Why not just make this a left join to your table1 and return record where the right side is null? Then you can just add these to the table... |
 |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2004-06-17 : 07:19:11
|
| Stay away from cursors....the performance in general is c**p...as you are experiencing!...search here for examples of horror stories. |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2004-06-17 : 07:49:10
|
quote: Originally posted by xdk1x Hi!I am going through table with a cursor. Some fields of the Cursor connected table should be compared to the Primary Keys (five fields) in another table. So that I can update the second table in case that the Primary Key exists and make an insert if not so.
If you can post the CREATE TABLE syntax for your table, with the PRIMARY KEY, I have a script here which will generate SQL for UPDATE/INSERT/DELETE to copy "delta" differences from SOURCE to DESTINATION tables without using cursors - if that would help give you an exampleKristen |
 |
|
|
|
|
|