Reputation:
I have this code:
IF (@@ROWCOUNT != 1)
THROW 50004,'mark_test - Problem setting test status to Marked',1
I know I can get the error message like this:
SET @ErrorMessage = ERROR_MESSAGE()
But how can I get the number 50004 ?
Upvotes: 1
Views: 538
Reputation: 93724
Use ERROR_NUMBER
function
Returns the error number of the error that caused the CATCH block of a TRY…CATCH construct to be run.
DEMO
BEGIN TRY
SELECT 1
UNION ALL
SELECT 1
IF ( @@ROWCOUNT != 1 )
THROW 50004, 'mark_test - Problem setting test status to Marked', 1
END TRY
BEGIN CATCH
SELECT Error_number=Error_number(),
Error_message=Error_message()
END CATCH
Result
Error_number Error_message
50004 mark_test - Problem setting test status to Marked
Upvotes: 1