0 Comments

 

Here is a function you can use to get the full stored procedure name (incl. schema name) within the current executing stored procedure:

 

if  object_id('dbo.GetFullSprocName') is not null
begin
    drop function dbo.GetFullSprocName
end
go

create function dbo.GetFullSprocName (@sprocId int)
returns varchar(255)
as
begin
    declare @FullSprocName as varchar(255)
    
    set @FullSprocName = (
        select        top 1 s.name + '.' + o.name
        from        sys.objects o with(nolock)
        inner join    sys.schemas s with (nolock) on o.schema_id = s.schema_id
        where        o.object_id = @sprocId
    )

    return @FullSprocName
end
go

To call this function use:

 

declare @sprocName varchar(128) = dbo.GetFullSprocName(@@PROCID)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts