Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Sun Foster
Aged Yak Warrior
515 Posts |
Posted - 2010-02-05 : 12:10:18
|
| What number should put after return in transation?nothing, 1 or 11?IF @@ERROR <> 0 BEGIN ROLLBACK TRAN return 11 END |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-05 : 12:12:19
|
| simply RETURN would do |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-02-05 : 12:44:19
|
| Our convention is to return 0 for success and any other value for error - i.e. a non-zero value indicates error and, usually, is a reference number for the type of error that occurred.We use unique numbers within the block of code to indicate the point at which the error was raised.But there are no hard-and-fast rules ... |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-05 : 12:46:22
|
| it comes handy when you need to check for status and then take some action after that based on it |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2010-02-05 : 13:43:47
|
Depending on what you are doing and how you use (if at all) the return code you can just do RETURN as suggested by Visakh. To go a step further, I like to return an error code. So I either capture @@ERROR or ERROR_NUMBER and return that. Presumably, if there are no error the result will be zero.For example:DECLARE @Error INT...SET @Error = @@ERRORIF @Error <> 0BEGIN ROLLBACK TRAN RETURN @ErrorEND |
 |
|
|
|
|
|