Reordering Nodes Within the Hierarchy

Reorganizing a hierarchy is a common maintenance task. You might often need to alter the tree structure by changing the parent-child relationships within the hierarchy. The hierarchyid type provides a GetReparentedValue method that makes it easy to handle this kind of maintenance. We will start by first relocating just a single node without disturbing any other nodes in the hierarchy. Then we’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 specifies the new parent (the target). Returning ...

Get Programming Microsoft® SQL Server™ 2008 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.