RAISERROR Syntax in a SQL Server Stored Procedure

Bobby P 221 Reputation points

I read about using the RAISERROR hack when using a SQL Server Stored Procedure that goes across a Linked Server.

Just wondering what the Syntax is for RAISERROR within a SQL Server Stored Procedured.

Thanks for your review and am hopeful for a reply.


No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Faizan Ahmad Khan 1 Reputation point

    RAISERROR used to define custom error message . this error message can be printed from stored procedure when validation failed

    RAISEERROR ('invalid ProductID' 5001, 2)

  2. LiHong-MSFT 9,996 Reputation points

    Hi,@Bobby P
    RAISERROR is used to throw an exception or error.
    For example,you can add ERROR CHECKS in stored procedure,like this:

    IF (@type_id IS NULL)  
       RAISERROR ('Parameter ''role_type_id'' can not be null.' , 16, 1) WITH NOWAIT  
       RETURN 1  

    Please refer to this document for more details.

    Best regards,

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

  3. Bobby P 221 Reputation points

  4. Bobby P 221 Reputation points

    Can anyone help me out here? This Job will run successfully for 3-4 weeks at a time and then hits this time-out issue out of nowhere it seems. It's driving me CRAZY!

    Any insight at all?!?!?