hierarchyid.GetLevel
tree navigation GetLevel
What changes
- Input
- hierarchyid instance and arguments
- Output or change
- smallint
- Return type
- SQL Server return type:smallint CLR return type:SqlInt16
Syntax at a glance
node.GetLevel ( )
Work example
Group nodes by their depth or enforce a maximum hierarchy level.
Compare the returned level with the root level expected by the application.
Check your work The root path has level zero and each child adds one level.
Practice SQL
Open in SQL FlowSELECT hierarchyid::Parse('/4/2/').GetLevel() AS depth;
Open Microsoft Learn for full syntax, permissions, and details for your version.