determining current procedure name | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

determining current procedure name

I am writing a procedure and would like to reference the name of the procedure within the code. How do I determine what the current procedure name is without hardcoding it into the content of the procedure. Let’s say I am creating a procedure named abc and I would like to print out message from within this procedure that say ‘procedure abc failed because of space.’. Do I have to explicitly set a variable to ‘abc’ or is there some method of obtaining the current procedure name without hardcoding. This way if I change the procedure name, I do not have to go and change the set variable statement within the procedure. Thank You,
Have a look at @@PROCID in BOL. I can’t verify this right now, but SELECT OBJECT_NAME(@@PROCID) should return the name. —
Frank Kalis
SQL Server MVP

Frank, Your @@PROCID suggestion works perfectly and returns the name of the current procedure. Now I won’t have to hardcode names in any of my procedures. Thanks You,