Hi All!
Hope you had a great summer! I was looking up the 'internets' for something and came across many people looking for a way to retrieve SQL Error Message based on an Error ID.
Here's a quick solution - nothing outstanding; but good-to-know script!
DECLARE @Error int
DECLARE @ErrorMessage varchar(800)
<... sql ...>
<... sql ...>
SET @Error = @@Error
IF @Error <> 0 SET @ErrorMessage = isnull((select [text] from sys.messages where message_id = @Error),'Error. Details not found.')
SELECT @Error as [Error ID], @ErrorMessage as [Error Message]
GO
Go
Go
Go. Execute.
Regards!
Please consider the environment before printing this blog! Go Green!
Hope you had a great summer! I was looking up the 'internets' for something and came across many people looking for a way to retrieve SQL Error Message based on an Error ID.
Here's a quick solution - nothing outstanding; but good-to-know script!
DECLARE @Error int
DECLARE @ErrorMessage varchar(800)
<... sql ...>
<... sql ...>
SET @Error = @@Error
IF @Error <> 0 SET @ErrorMessage = isnull((select [text] from sys.messages where message_id = @Error),'Error. Details not found.')
SELECT @Error as [Error ID], @ErrorMessage as [Error Message]
GO
Go
Go
Go. Execute.
Regards!
Please consider the environment before printing this blog! Go Green!
Comments