views:

119

answers:

1

This code here does not work when I try to find a single parent node

declare @val hierarchyid
select @val = dbo.GetHierarchyIDbyID(30)

--get the parent
select * from NodeHierarchy
where @val.GetAncestor(NodeHierarchyID) = 1

How would you go about finding the parent?

+1  A: 

Assuming the name of the field containing the hierarchy ID is "hid", you could do the following:

DECLARE @val HIERARCHYID
SELECT @val = dbo.GetHierarchyIDbyID(30)
SELECT * FROM NodeHierarchy WHERE hid = @val.GetAncestor(1)

Darvis Lombardo
Thanks I tried it and it worked
Luke101