Querying the Hierarchy
Now that you’ve populated the hierarchy, you should query it to view the data and verify the hierarchy was populated correctly. However, If you query the hid
value directly, you see only its binary representation, which is not very meaningful. To view the Hierarchyid
value in a more useful manner, you can use the ToString
method, which returns a logical string representation of the Hierarchyid
. This string representation is shown as a path with a slash sign used as a separator between the levels. For example, you can run the following query to get both the binary and logical representations of the hid
value:
select cast(hid as varbinary(6)) as hid, substring(hid.ToString(), 1, 12) as ...
Get Microsoft® SQL Server 2012 Unleashed 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.