@@NESTLEVEL (T-SQL)

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

This is the result:

Outer Level

-----------------

1                

  

Inner Level

-----------------

2                

  

See Also
Creating a Stored Procedure Configuration Functions
@@TRANCOUNT  

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.