-1

I am using HierarchyId in SQL server and I am referring the the article below to to get all the ancestors

https://technet.microsoft.com/en-us/library/bb677212%28v=sql.105%29.aspx

I have following code:

  DECLARE @last_child HIERARCHYID
     select *
     FROM   dbo.Geography AS g
     WHERE  @last_child.GetAncestor(1) = 0x58

     SELECT @last_child

I do have a node with id 0x58 in DB and it does have a child. However, @last_child is coming back null constantly for some reason. Am I doing anything wrong?

Lost
  • 12,007
  • 32
  • 121
  • 193

1 Answers1

0

Ok. I am still not sure what is wrong with the code above. However, I found and alternative method to find all the children for a particular parent node. Code is posted below:

SELECT *
FROM Geography
WHERE GeographyNode.IsDescendantOf(0x58) = 1
Lost
  • 12,007
  • 32
  • 121
  • 193