Skip to content

Latest commit

 

History

History
75 lines (65 loc) · 2.9 KB

procid-transact-sql.md

File metadata and controls

75 lines (65 loc) · 2.9 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic f1_keywords helpviewer_keywords dev_langs
@@PROCID (Transact-SQL)
@@PROCID (Transact-SQL)
VanMSFT
vanto
09/18/2017
sql
t-sql
reference
@@PROCID
@@PROCID_TSQL
stored procedures [SQL Server], identification numbers
UDTs [SQL Server], object identifiers
@@PROCID function
user-defined functions [SQL Server], object identifiers
triggers [SQL Server], object identifiers
identification numbers [SQL Server], modules
IDs [SQL Server], modules
module object identifiers [SQL Server]
TSQL

@@PROCID (Transact-SQL)

[!INCLUDE SQL Server Azure SQL Database Azure SQL Managed Instance]

Returns the object identifier (ID) of the current [!INCLUDEtsql] module. A [!INCLUDEtsql] module can be a stored procedure, user-defined function, or trigger. @@PROCID cannot be specified in CLR modules or the in-process data access provider.

:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions

Syntax

@@PROCID  

Return Types

int

Examples

The following example uses @@PROCID as the input parameter in the OBJECT_NAME function to return the name of the stored procedure in the RAISERROR message.

USE AdventureWorks2022;  
GO  
IF OBJECT_ID ( 'usp_FindName', 'P' ) IS NOT NULL   
DROP PROCEDURE usp_FindName;  
GO  
CREATE PROCEDURE usp_FindName  
    @lastname VARCHAR(40) = '%',   
    @firstname VARCHAR(20) = '%'  
AS  
DECLARE @Count INT;  
DECLARE @ProcName NVARCHAR(128);  
SELECT LastName, FirstName  
FROM Person.Person   
WHERE FirstName LIKE @firstname AND LastName LIKE @lastname;  
SET @Count = @@ROWCOUNT;  
SET @ProcName = OBJECT_NAME(@@PROCID);  
RAISERROR ('Stored procedure %s returned %d rows.', 16,10, @ProcName, @Count);  
GO  
EXECUTE dbo.usp_FindName 'P%', 'A%';  

See Also

CREATE FUNCTION (Transact-SQL)
CREATE PROCEDURE (Transact-SQL)
CREATE TRIGGER (Transact-SQL)
Metadata Functions (Transact-SQL)
sys.objects (Transact-SQL)
sys.sql_modules (Transact-SQL)
RAISERROR (Transact-SQL)