RAISERROR Syntax in a SQL Server Stored Procedure

Bobby P 221 Reputation points
2022-01-18T03:27:23.853+00:00

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.

Thanks!

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,551 questions
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Faizan Ahmad Khan 1 Reputation point
    2022-01-18T04:05:35.597+00:00

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

    RAISEERROR ('invalid ProductID' 5001, 2)

    0 comments No comments

  2. LiHong-MSFT 10,046 Reputation points
    2022-01-18T06:47:18.067+00:00

    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)  
      BEGIN  
       RAISERROR ('Parameter ''role_type_id'' can not be null.' , 16, 1) WITH NOWAIT  
       RETURN 1  
      END  
    

    Please refer to this document for more details.

    Best regards,
    LiHong


    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.

    0 comments No comments

  3. Bobby P 221 Reputation points
    2022-01-22T17:23:53.933+00:00

  4. Bobby P 221 Reputation points
    2022-01-22T17:30:20.873+00:00

    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?!?!?