I have a stored procedure which is nested in several other stored procedure. Is there a way to tell (inside the internal stored procedure) which is the caller?
CREATE PROC int_proc
AS
SELECT int_name = OBJECT_NAME(@@PROCID)
,ext_name = 'How can I tell which is the ext_proc name?'
,nestlevel = @@NESTLEVEL
GO
CREATE PROC ext_proc1
AS
SELECT ext_name = OBJECT_NAME(@@PROCID),nestlevel = @@NESTLEVEL
EXECUTE int_proc
GO
CREATE PROC ext_proc2
AS
SELECT ext_name = OBJECT_NAME(@@PROCID),nestlevel = @@NESTLEVEL
EXECUTE int_proc
GO
EXEC ext_proc1
EXEC ext_proc2
I’m using SQL-Server 2005
No, there isn’t. The “stack” isn’t available to us
Why do you need this? FYI, I pass in @@PROCID to a common error logging stored procedure. So there are some uses for this. But none natively in SQL