| title | GetLevel (Database Engine) | ||
|---|---|---|---|
| description | GetLevel (Database Engine) | ||
| author | MikeRayMSFT | ||
| ms.author | mikeray | ||
| ms.date | 07/22/2017 | ||
| ms.service | sql | ||
| ms.subservice | t-sql | ||
| ms.topic | reference | ||
| f1_keywords |
|
||
| helpviewer_keywords |
|
||
| dev_langs |
|
[!INCLUDE SQL Server Azure SQL Database Azure SQL Managed Instance]
Returns an integer that represents the depth of the node this in the tree.
-- Transact-SQL syntax
node.GetLevel ( )
-- CLR syntax
SqlInt16 GetLevel ( )
[!INCLUDEsql-server-tsql-previous-offline-documentation]
SQL Server return type:smallint
CLR return type:SqlInt16
Used to determine the level of one or more nodes or to filter the nodes to members of a specified level. The root of the hierarchy is level 0.
GetLevel is useful for breadth-first search indexes. For more information, see Hierarchical Data (SQL Server).
The following example returns a text representation of the hierarchyid, and then the hierarchy level as the EmpLevel column for all rows in the table:
SELECT OrgNode.ToString() AS Text_OrgNode,
OrgNode.GetLevel() AS EmpLevel, *
FROM HumanResources.EmployeeDemo; The following example returns all rows in the table at the hierarchy level 2:
SELECT OrgNode.ToString() AS Text_OrgNode,
OrgNode.GetLevel() AS EmpLevel, *
FROM HumanResources.EmployeeDemo
WHERE OrgNode.GetLevel() = 2; The following example returns the root of the hierarchy level:
SELECT OrgNode.ToString() AS Text_OrgNode,
OrgNode.GetLevel() AS EmpLevel, *
FROM HumanResources.EmployeeDemo
WHERE OrgNode.GetLevel() = 0; The following code snippet calls the GetLevel() method:
this.GetLevel() hierarchyid Data Type Method Reference
Hierarchical Data (SQL Server)
hierarchyid (Transact-SQL)