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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 What number should put after return in transation?

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
Go to Top of Page

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 ...
Go to Top of Page

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
Go to Top of Page

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 = @@ERROR

IF @Error <> 0
BEGIN
ROLLBACK TRAN
RETURN @Error
END
Go to Top of Page
   

- Advertisement -