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

I want to run multiple query statements(INSERT,UPDATE,DELETE) in a Single Stored Procedure.

But the Delete query is not working.

Any suggestions...
Posted

if you want single sp for crud operaton then
you should define @Task variable and use if conditions like below pass value to sp for task also with other parameters...
SQL
if @Task = 1 
Begin
//insert
return
end 
elseif @Task = 2 
Begin
//update
return
end
elseif @Task = 3
Begin
//Delete
return
end

Happy Coding!
:)
 
Share this answer
 
You can put in as many queries as you like in a stored procedure.
Check that you are passing the right query parameters to delete the row and that the row exists in the table.
 
Share this answer
 
Without seeing your queries or table structures, it's difficult to give you a definitive answer... in addition to what Abhinav S says, it might also be that the delete query is failing due to key constraints (primary key/foreign key) on the row you are trying to delete.
 
Share this answer
 
Comments
PRAKASH_N 20-May-13 3:20am    
my query is

alter procedure RunIssue
(
@id int,
@Cname varchar(20)
)
as
begin

update EmpTab set empName=@Cname where id=@id

delete CustDetail where id=@id

insert into tmpTable(id,cname) values(@id,@Cname)

delete SubIssue

end
_Damian S_ 20-May-13 19:58pm    
Okay, so the question is, what's in CustDetail table for the id you are looking to delete... for instance, do they have a linked record in CustOrders or CustAddress (examples - your table names will vary)?
 
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