Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Best way to implement transactions in a procedure with If statements


Best way to implement transactions in a procedure with If statements

Author
Message
hiram.osiris
hiram.osiris
Valued Member
Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)Valued Member (60 reputation)

Group: General Forum Members
Points: 60 Visits: 424
Hello, I'm writing a complex stored procudere with a lot of IF statements, inside of each IF statement is an Update, Delete or Insert Operation. Example:

CREATE PROC Proc1
@Var1 INT,
@Var2 INT,
@Var3 INT
AS
IF @var1 IS NOT NULL AND @Var2 IS NOT NULL
BEGIN
Update some table
Insert INTO some other table
END
IF @Var1 IS NULL AND @Var2 IS NOT NULL
BEGIN
delete from some table
END
IF @var3 IS NOT NULL AND @Var1 IS NULL AND @Var2 IS NULL
BEGIN
Update Some other table
END



What would be the best approach for using Transactions? Open a transaction inside each statement?
Greetings Ermm
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search