hierarchyid.IsDescendantOf
tree predicate IsDescendantOf
What changes
- Input
- two hierarchyid values
- Output or change
- bit
- Return type
- SQL Server return type:bit CLR return type:SqlBoolean
Syntax at a glance
child. IsDescendantOf ( parent )
Work example
Filter nodes that belong to a selected parent subtree.
Pass the ancestor path and test whether the ancestor itself should remain in the result.
Check your work IsDescendantOf returns true for the same node as well as for its descendants.
Practice SQL
Open in SQL FlowDECLARE @parent hierarchyid = hierarchyid::Parse('/4/'); DECLARE @node hierarchyid = hierarchyid::Parse('/4/2/'); SELECT @node.IsDescendantOf(@parent) AS in_subtree;
Open Microsoft Learn for full syntax, permissions, and details for your version.