From: Roy Goldhammer on
Hello there.

Is there a way to know the name of procedure I run?


From: Andrea Montanari on
hi Roy,
Roy Goldhammer wrote:
> Hello there.
>
> Is there a way to know the name of procedure I run?

I do not understand the context of the requirement, but perhaps
OBJECT_NAME(@@PROCID)) can do the trick, similarly to

SET NOCOUNT ON;
USE tempdb;
GO
CREATE PROCEDURE dbo.usp_MyProcedure
AS BEGIN
DECLARE @proc sysname;
SET @proc = CAST(OBJECT_NAME(@@PROCID) AS sysname);

PRINT 'the executed code is: ' + @proc;
SELECT @proc;
END;
GO
EXEC dbo.usp_MyProcedure;
GO
DROP PROCEDURE dbo.usp_MyProcedure;

regards
--
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz
DbaMgr2k ver 0.21.1 - DbaMgr ver 0.65.1 and further SQL Tools
http://www.hotelsole.com - http://www.hotelsolericcione.de
--------- remove DMO to reply


From: Dan Guzman on
> SET @proc = CAST(OBJECT_NAME(@@PROCID) AS sysname);

Since the OBJECT_NAME function returns sysname (nvarchar(128)), I think this
can be simplified without the CAST:

SET @proc = OBJECT_NAME(@@PROCID);

--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/