| title | @@PROCID (Transact-SQL) | Microsoft Docs | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| ms.custom | |||||||||
| ms.date | 03/16/2017 | ||||||||
| ms.prod | sql-non-specified | ||||||||
| ms.reviewer | |||||||||
| ms.suite | |||||||||
| ms.technology |
|
||||||||
| ms.tgt_pltfrm | |||||||||
| ms.topic | language-reference | ||||||||
| f1_keywords |
|
||||||||
| dev_langs |
|
||||||||
| helpviewer_keywords |
|
||||||||
| ms.assetid | 0d4882c7-edb8-49b1-a470-2c7497b8998f | ||||||||
| caps.latest.revision | 43 | ||||||||
| author | BYHAM | ||||||||
| ms.author | rickbyh | ||||||||
| manager | jhubbard |
[!INCLUDEtsql-appliesto-ss2008-asdb-xxxx-xxx_md]
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.
Transact-SQL Syntax Conventions
@@PROCID
int
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 AdventureWorks2012;
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%';
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)