Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Current executing procedure name

Is it possible to get the name of the current Stored Procedure in MS SQL Server?

Maybe there is a system variable or function like GETDATE()?

like image 593
Sergey Metlov Avatar asked May 17 '11 17:05

Sergey Metlov


People also ask

Which command is used for executing procedure?

The EXEC command is used to execute a stored procedure, or a SQL string passed to it. You can also use full command EXECUTE which is the same as EXEC.

What is procedure name in SQL?

SQL Server stored procedure is a batch of statements grouped as a logical unit and stored in the database. The stored procedure accepts the parameters and executes the T-SQL statements in the procedure, returns the result set if any.

What is execute stored procedure?

What is a Stored Procedure? A stored procedure is a prepared SQL code that you can save, so the code can be reused over and over again. So if you have an SQL query that you write over and over again, save it as a stored procedure, and then just call it to execute it.

How is a procedure executed?

Expand the database that you want, expand Programmability, and then expand Stored Procedures. Right-click the user-defined stored procedure that you want and select Execute Stored Procedure. In the Execute Procedure dialog box, specify a value for each parameter and whether it should pass a null value.


2 Answers

You may try this:

SELECT OBJECT_NAME(@@PROCID) 

Update: This command is still valid on SQL Server 2016.

like image 146
Alireza Maddah Avatar answered Sep 18 '22 20:09

Alireza Maddah


OBJECT_SCHEMA_NAME(@@PROCID) + '.' + OBJECT_NAME(@@PROCID) 
like image 28
karthik Avatar answered Sep 19 '22 20:09

karthik