by Andrew Jackson
15. August 2009 11:50
The following SQL will report the name of the currently executing stored procedure
/* Begin */
PRINT ISNULL(OBJECT_NAME(@@PROCID), '<none>')
/* End */
To fetch this into a variable use :
/* Begin */
DECLARE @procedure_name VARCHAR(255)
SET @procedure_name = ISNULL(OBJECT_NAME(@@PROCID), '<none>')
/* End */
The key to this is @@PROCID, however, this returns NULL if not executing in a stored procedure, the ISNULL prevents a NULL value being used