Transact-SQL Reference

@@NESTLEVEL

Returns the nesting level of the current stored procedure execution (initially 0).

Syntax

@@NESTLEVEL

Return Types

integer

Remarks

Each time a stored procedure calls another stored procedure, the nesting level is incremented. When the maximum of 32 is exceeded, the transaction is terminated.

Examples

This example creates two procedures: one that calls the other, and one that displays the @@NESTLEVEL setting of each.

CREATE PROCEDURE innerproc as 
select @@NESTLEVEL AS 'Inner Level'
GO

CREATE PROCEDURE outerproc as 
select @@NESTLEVEL AS 'Outer Level'
EXEC innerproc
GO

EXECUTE outerproc
GO

Here is the result set:

Outer Level 
----------------- 
1                 

Inner Level 
----------------- 
2                 

See Also

Configuration Functions

Creating a Stored Procedure

@@TRANCOUNT