How to trap SQL Server Error Messages?

  • To check for an error you use @@ERROR immediately after the given statement:

    IF @@ERROR <> 0 <do something>

    To raise a custom message, you can use the RAISERROR command:

    RAISERROR( 'ERROR: bla-bla-bla', 16, -1 )

    You could also create custom error messages in sysmessages and call those by number:

    RAISERROR( 50001, 16, -1 )

Viewing post 1 (of 2 total)

You must be logged in to reply to this topic. Login to reply