sql server 2008

  • how I can capture an error message returned by a stored procedure, and puts it into a variable.

    thank you

  • The best way to do this is by using TRY...CATCH... blocks.

    Read more about them in here: http://msdn.microsoft.com/en-us/library/ms175976(v=sql.100).aspx

    Or search on the internet for more information and come back with any questions that you have.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • BEGIN TRY

    -- Generate a divide-by-zero error.

    SELECT 1/0;

    END TRY

    BEGIN CATCH

    SELECT

    ERROR_NUMBER() AS ErrorNumber

    ,ERROR_SEVERITY() AS ErrorSeverity

    ,ERROR_STATE() AS ErrorState

    ,ERROR_PROCEDURE() AS ErrorProcedure

    ,ERROR_LINE() AS ErrorLine

    ,ERROR_MESSAGE() AS ErrorMessage;

    END CATCH;

    GO

    Programming[/url]

Viewing 3 posts - 1 through 2 (of 2 total)

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