Get objectname inside SP | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Get objectname inside SP

Hi, I need your inputs to pass SP name when i am getting error. I am going to use sysmessage for user defined error message and whenever error happen i would like to pass SP name in which error is raise. Take an example i have SP as below Create procedure P_Raiserror
as Declare @objectname varchar(20) Set @objectname =’P_Raiserror’ /*** I would like to remove this hardcoding***/ IF @@Error<>0 Begin
Raiserror(50005,16,1,@objectname)
End GO
I would like to remove hardcoding of objectname so i can create Raiserror generic. Please provide me your inputs. Thanks and Regards Ravi K.


SELECT name FROM sysobjects where id = @@PROC_ID should return the name of the procedure.

Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Ich unterstütze PASS Deutschland e.V. http://www.sqlpass.de)

and this as well Select object_name(@@PROC_ID)
Madhivanan Failing to plan is Planning to fail
]]>