Click here to Skip to main content
15,914,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to select the records from one table based on some condition and that table data will be cleared.It is to be done in Single Stored Procedure.But it returns empty datatable because of delete query.How can i implement this?

Eg. My query is like this,

Select * from table1 where id = 1
Delete from table1 where id = 1

How can i get the records in DAL and as well as datas to be deleted in table.


Thanks in Advance..
Posted
Comments
CHill60 11-Jun-15 9:36am    
Have the SP return a table variable and do the select into it

1 solution

Probably the easiest way is to select into a temporary table, then do the delete the query the temporary table to get the SP output e.g.
SQL
create procedure sp_vksvpp
as
begin
    Select * into #temp from table1 where id = 1
    Delete from table1 where id = 1
    select * from #temp
end
go

Alternatively you could do something with a After Delete trigger but that is probably overkill
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900