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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Keeping ignored records

Author  Topic 

stoot98
Starting Member

1 Post

Posted - 2007-07-27 : 11:12:48
Hi Guys

I have an sql query which basically moves records from one table (a "Load" table) to another (a "Data" table) ignoring records that already exist in the Data table that match a specified key. This is done using the WHERE NOT EXISTS function so it only inserts the unique ones. My problem is that I would like to move the ignored records (i.e. the ones which DO match and arent inserted) to another table (call it "Load_Ignored") so these can be tracked.

At the moment the only way i can think of doing this is to rerun the exact same query but with a WHERE EXISTS clause instead of NOT EXISTS to move the ones that were ignored. But this seems like it will take double the time as all the original records remain in the Load table. Is there a better way?

Thanks in advance, any help is appreciated!

Stoot

JoeNak
Constraint Violating Yak Guru

292 Posts

Posted - 2007-07-27 : 12:55:06
You can use an INNER JOIN or a WHERE IN. You'd have to check the execution plans to see which method is 'best'
Go to Top of Page
   

- Advertisement -