29 August, 2013
0 Comments
1 category
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)
Tags: T-SQL
Category: Uncategorized