Suppose you want to find out the name of the procedure that calls the procedure being executed,you can use system function @@PROCID which returns the object id of the current procedure.
Consider the following procedures. test1 calls the procedure test2 which actually logs some informations to the log table. What, if you want to know the calling procedure name also?. test2 accepts @@procid as input parameter and with the help of the object_name function, the name of the calling procedure is known inside the procedure test2. It is also possible to know in any number of procedures. Note that when you execute the procedure test1, it calls both test2 and test3 who know the calling procedure name.
create procedure test1
declare @procid int
exec test2 @procid
exec test3 @procid
create procedure test2(@procid int)
--Log the source if any error
insert into log_table(procedure_name,column_list)
create procedure test3(@procid int)
select object_name(@procid) as calling_procedure
Tags: t-sql, sql_server, procedure, tsql, BRH, #TSQL, @@procid, #SQLServer,
Is there a way to find this info without passing @@ProcID ?
I dont think there is a way without passing it. Otherwise you may need to pass the procedure name directly.