Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple updates in one stored procedure!

Status
Not open for further replies.

angst11

Programmer
Sep 5, 2001
25
0
0
US
Is there a way to have multiple updates in one stored procedure! I have ten update statements that need to be executed based on the parameters that are passed! Can this be done in one stored procedure?
 
Yes, no problem. E.g.

create procedure p(@nv1 varchar(20),@pk1 int,
@nv2 varchar(20),@pk2 int)
as
set nocount on
update t1 set c1 = @nv1 where pk = @pk1
update t2 set c2 = @nv2 where pk = @pk2



Uou can add as many statement as you need.
 
You can also put them all in one transaction so if any one fails they will all be rolled back.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top