Wednesday, June 26, 2013

Get all the child for the selected item : HierarchyId

 Declare @mgr HierarchyId
 select @mgr=HierarchyID from Hierarchies WHERE HierarchyID=hierarchyid::GetRoot()
Select H1.*,(Select CASE WHEN count(1)>1 THEN 1 ELSE 0 END FROM Hierarchies AS H2 WHERE H2.HierarchyID.IsDescendantOf(H1.HierarchyID)=1) AS IsChild from Hierarchies AS H1 WHERE HierarchyID.IsDescendantOf(@mgr)=1

No comments:

Post a Comment