Retreiving SP name using T-SQL Script

Some of us when executing a Store Procedure in SQL Server want to insert a record into the table with the current procedure name that is executed (this can especially useful when the procedure name is stored in the exception tables when there is an error in the execution of the SP)

Below is the query to find the current proc name using T-SQL Script:

SELECT ISNULL(OBJECT_NAME(@@PROCID), 'MYPROC')

In the SP , we can write as

INSERT INTO Exception_Table(ProcedureName)
SELECT ISNULL(OBJECT_NAME(@@PROCID), 'MYPROC')

Have a nice day !

Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: