I have a stored procedure that works with no issues, that is the return code is 0. In some cases I RAISERROR a user defined error (> 50000). In those cases the return is -6. I am just curious, what does -6 mean? I do not set the return code in the procedure, so this number is SQL Server (system) generated.
I found this statement:
Whether these negative numbers have any meaning, is a bit difficult to tell. It used to be the case, that the return values -1 to -99 were reserved for system-generated return values, and Books Online for earlier versions of SQL Server specified meanings for values -1 to -14. However, Books Online for SQL 2000 is silent on any such reservations, and does not explain what -1 to -14 would mean.
Does anyone know the "hidden" meanings to these return codes?
I am using SQL Server 2008 R2.
OK, I found this...
Return value from a stored proc on error
If you have a RETURN statement with an explicit return value, that is of course the return value.
But if there is no RETURN statement, but an error occurs during execution, the return value is 10 minus the severity level of the error. Division by zero is level 16, thus the return value is -6. Permissions errors are typical level 14, thus the return value is -4.
In my case, the severity of the error I was raising was 16, so 10 - 16 = -6.
Thanks everyone for thier input.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With