I would like to save the error message that SQL-Server generates when an error occurs.
I am able to select @@ERROR to get the the error number and I am then able to look up the generic error message from the sysmessages table. However, the sysmessages is generic and does not have, for example, the name of the table that was not found.
See code below:
select * from NON_EXISTANT
go
select * from master.dbo.sysmessages
where error = (select @@error)
Results in this:
Server: Msg 208, Level 16, State 1, Line 1
Invalid object name 'NON_EXISTANT'.
error severity dlevel description
----------------------------------------------------
208 16 0 Invalid object name '%.*ls'.
As you can see the if I saved the data from the SYSMESSAGES table to a variable, I would not get 'NON_EXISTANT' but rather '%.*ls'.
How can I access the error message :
"Invalid object name 'NON_EXISTANT'." in T-SQL.
Thanks for any help.
Brad
[sig][/sig]
I am able to select @@ERROR to get the the error number and I am then able to look up the generic error message from the sysmessages table. However, the sysmessages is generic and does not have, for example, the name of the table that was not found.
See code below:
select * from NON_EXISTANT
go
select * from master.dbo.sysmessages
where error = (select @@error)
Results in this:
Server: Msg 208, Level 16, State 1, Line 1
Invalid object name 'NON_EXISTANT'.
error severity dlevel description
----------------------------------------------------
208 16 0 Invalid object name '%.*ls'.
As you can see the if I saved the data from the SYSMESSAGES table to a variable, I would not get 'NON_EXISTANT' but rather '%.*ls'.
How can I access the error message :
"Invalid object name 'NON_EXISTANT'." in T-SQL.
Thanks for any help.
Brad
[sig][/sig]