December 13, 2011 at 9:45 am
How are the Return statements being used? Are they returning error codes, or are they just aborting the procedure so no further code is run in it?
I generally avoid using Return, except in debugging. (Or in UDFs, but that's a different use.)
What fix is best will depend on how Return is being used.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
December 13, 2011 at 9:56 am
It is used Just to abort other scripts,
No codes are returned.
December 13, 2011 at 9:59 am
Then what you probably want is Try Catch and Raiserror, like your proposed solution.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
December 13, 2011 at 10:58 am
each exit is going to need a commit:
IF @condition =1
BEGIN
--do stuff (like you said...either raise an error or commit.
COMMIT TRAN --RaisError?
RETURN
END
IF @condition =2
BEGIN
--do stuff
COMMIT TRAN --RaisError?
RETURN
END
Lowell
December 13, 2011 at 11:19 am
The exits needing commits depends on what you're trying to do.
If a condition calls for rolling back on a failure, then raising an error, cutting over to the Catch block, and rolling back there, won't require a separate rollback/commit at all.
If the conditions are sequential instead of exclusive, then you don't need a commit at each one, just one at the end before the End Try statement.
It depends on what the specific code is designed to do.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 5 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply