If I am within a nested stored procedure, I would like to be able to get the procedure ID of the procedure that is one level up.
Example:
create proc procedure1
as
print 'Current proc id: ' + @@PROCID
print 'Parent proc id: ' + @@PROCID_PARENT --or something?
go
create proc procedure2
as
exec procedure1
go
exec procedure2
would give results something like:
Current proc id: 93440434
Parent proc id: 10022237
I have a stored procedure that might be executed from within several other stored procedures, and I’d like to be able to know which procedure is executing the child procedure. Is this possible?
There’s no built in way to retrieve this. You’d need to pass the id,
@@procid, or the name,object_name(@@procid), of the parent into the child as another parameter.