Delete with CTE



create table Products(id int, pname varchar(10))
create table Price(id int, price int)
create table stock(ids int, sname varchar(10))

Insert into Products values (1,'a1'),(2,'a2'),(3,'a3'),(4,'a')

Insert into price values (1,1),(2,2),(3,2),(4,2),(5,3)
Insert into stock values (1,'a1'),(2,'a2'),(3,'a3'),(14,'a'),(15,'b15')

declare @intprice int=2

;with mycte as
(
Select * from stock WHERE IDs IN (
SELECT pt.ID from Products pt
 INNER JOIN Price pr
 ON pt.ID = pr.ID
 Where pr.price= @intprice )
)

 Delete from mycte
 Select * from stock

drop table Products
 drop table Price
 drop table Stock
 

http://social.msdn.microsoft.com/Forums/en-US/920a2b62-1435-4caf-9187-0d1d90eae41e/delete-multiple-records?forum=transactsql

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s