Answered by:
SQL 2008 HierarchyID data type  example and questions

Ok, looking at this example
http://www.codeproject.com/Tips/740553/HierarchyIDinSQLServer
Why is the NodeText value for Nikki "/1.2/" but Steve and Alex is "/1.1/" and "/1.1.1/"
Seems like the NodeText value for Nikki would be "/1.1.1.1/" would it not?
Question
Answers

Hi,
* Inserting a row as the least descendant node using (NULL, NULL)
* Inserting a row as a greater descendant node using (@Child1, NULL)
* Inserting a row between two existing nodes using (@Child1, @Child2)
Now we can go beck to your question:
1. we insert Johnny (least descendant node) => 1
2. Robert , which is greater descendant node of Johnny => 2
3. Alex, is insert between two existing nodes Johnny and Robert, therefore => less then 2 and more then 1 = 1.1 (this is not less using number value but format value, we can not use 2.1 but we can use 1.1 for "more then 1, on the same level")
4. Niki insert between Alex and Robert => more then 1.1 and less then 2 => 1.2 since we already have 1.1
* If we will continue to insert between 1.2 and 2 then we get 1.3 between 1.3 to 2 is 1.4 ...
5. Steve insert between Alex and Niki => between 1.1 and 1.2 => 1.1.1
Is this explain the issue?
* This can give you much more understanding on using hierarchical tree without the HierarchyId. This solution was wrriten in 2001 and it almost have the same format as HierarchyId. It can give some insight I think.
http://ariely.info/Blog/tabid/83/EntryId/135/SortingParentChildrensdataasanhierarchicaltree.aspx
[Personal Site] [Blog] [Facebook]
All replies

Hi,
* Inserting a row as the least descendant node using (NULL, NULL)
* Inserting a row as a greater descendant node using (@Child1, NULL)
* Inserting a row between two existing nodes using (@Child1, @Child2)
Now we can go beck to your question:
1. we insert Johnny (least descendant node) => 1
2. Robert , which is greater descendant node of Johnny => 2
3. Alex, is insert between two existing nodes Johnny and Robert, therefore => less then 2 and more then 1 = 1.1 (this is not less using number value but format value, we can not use 2.1 but we can use 1.1 for "more then 1, on the same level")
4. Niki insert between Alex and Robert => more then 1.1 and less then 2 => 1.2 since we already have 1.1
* If we will continue to insert between 1.2 and 2 then we get 1.3 between 1.3 to 2 is 1.4 ...
5. Steve insert between Alex and Niki => between 1.1 and 1.2 => 1.1.1
Is this explain the issue?
* This can give you much more understanding on using hierarchical tree without the HierarchyId. This solution was wrriten in 2001 and it almost have the same format as HierarchyId. It can give some insight I think.
http://ariely.info/Blog/tabid/83/EntryId/135/SortingParentChildrensdataasanhierarchicaltree.aspx
[Personal Site] [Blog] [Facebook]


You are most welcome :)
[Personal Site] [Blog] [Facebook]