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
 SQL Server Development (2000)
 Delete Statement

Author  Topic 

RichardSteele
Posting Yak Master

160 Posts

Posted - 2004-01-11 : 04:33:26
I have two tables: stock_local and stock_remote. I need to delete any records in stock_remote that are no longer in stock_local. The key field that relates the two is catnum.

What would the delete statement look like that would do this job?

Many thanks.

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2004-01-11 : 05:18:35
DELETE FROM stock_remote
WHERE catnum NOT IN (SELECT catnum FROM stock_local)



Damian
Go to Top of Page

RichardSteele
Posting Yak Master

160 Posts

Posted - 2004-01-11 : 19:09:05
Thanks!

Now what would the code look like if I want to delete those records where the number is found but the stock_remote.xflag is not the same as stock_local.xflag?

Many thanks in advance.
Go to Top of Page

Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2004-01-11 : 20:04:40
delete from stock_remote from stock_remote t2 left join stock_local t1
on t2.catnum=t1.catnum and t2.xflag=t1.xflag
where t1.catnum is null
Go to Top of Page
   

- Advertisement -