How do you capture the error string in tsql?

  • @@ERROR only indicates an error has occurred. How do you capture the corresponding error string (which is usually printed in query analyzer)? I am not looking for the text representation of error xyz, but instead the string which contains the runtime error message.

    Is there a different variable which holds this information?

    Regards,

    Joshua

  • Not sure if I understand.

    Are you searching for the table sysmessages in master?

    Frank

    http://www.insidesql.de

    http://www.familienzirkus.de

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Your right, I should clarify.

    I have a stored procedure which converts data, essentially moving it from one table to another. I check the @@error variable to detect when my logic fails (an insert for example) and rollback the transaction. I then log the problem in another table and continue processing.

    If an insert (for example) failed because of a primary key constraint, it would be nice to know which constraint caused the problem for that particular row. I am looking to capture the runtime error that occurs for each iteration.

    Any ideas?

  • Save @@ERROR in a @variable if is not 0 and then

    select description from master.dbo.sysmessages where error = @variable

    HTH


    * Noel

  • sysmessages only contains the generic error message, without references to the particular objects.

    For example: Unclosed quote before the character string %.*ls.

    Is that specific enough?

Viewing 5 posts - 1 through 4 (of 4 total)

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