Invalid error number returned by system SPs

  • if i try to execute a system SP like 'sp_addmessage' then the value of @@error is 0 instead of the actual error number which should be 15009.

    for other scenarios in case of errors i get the actual error number in @@error.

    similiarly for other sp_ Stored Procs if an error is returned then i am not able to get its error number.

    However when i give the command raiseerror(15009,16,1) and then if i check the value of @@error in this case i get the error number.

     

     

    please help.....

     

  • system stored procedures use return code value for success or failure. @@error is erased with return statement.

    Sample:

    use pubs

    go

    create proc sperrtest as

     raiserror(15043,16,1)

     select @@error

     return (0)

    go

    declare @returncode int

    exec @returncode=sperrtest

    select @returncode, @@error

    go

    drop proc sperrtest

     

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

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