Reordering Nodes within the Hierarchy

Reorganizing the nodes within the tree structure is a common maintenance task when working with hierarchies. You might need to alter the tree structure by adjusting the parent-child relationships within the hierarchy. The hierarchyid type provides a GetReparentedValue method that makes it easy to handle this kind of maintenance. You will start by first relocating just a single node without disturbing any other nodes in the hierarchy. Then you’ll relocate an entire subtree (that is, all of a node’s descendant nodes).

The GetReparentedValue Method

You invoke the GetReparentedValue method on the node you want to move, passing in two parameters. The first specifies the original parent (the source), and the second ...

Get Programming Microsoft® SQL Server® 2012 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.