Returns the nesting level of the current stored procedure execution (initially 0).
@@NESTLEVEL
integer
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.
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
This is the result:
Outer Level
-----------------
1
Inner Level
-----------------
2
Creating a Stored Procedure | Configuration Functions |
@@TRANCOUNT |