SQL Flow Field Guide

@@NESTLEVEL

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

call-stack depth

What changes

Input
module nesting depth
Output or change
int
Return type
int

Syntax at a glance

@@NESTLEVEL

Work example

Check nested procedure or trigger depth during a call-chain investigation.

Read in the same session and compare before and after a controlled session setting change.

Check your work Compare values at entry and return boundaries because nested calls change the level.

Open Microsoft Learn for full syntax, permissions, and details for your version.