Displaying Hierarchical Data in SSMS

You can view hierarchical data via SSMS. To view a textual representation of the EmployeeHierarchy table, enter and execute the following code:

Select Name, Position, OrganizationLevel.ToString() From EmployeeHierarchy;

This will list each employee, along with his or her position and a text representation of that person's location in the hierarchy. The ToString method returns your HierarchyID, using a single slash character (/) to represent the root node. Looking at Bob and Andy, you can see that they are siblings and children of Kay. Figure A-2 shows the results of the preceding query in SSMS. The third column shows each person's location in the hierarchy. The delimited string that you see is termed a ...

Get Foundations of SQL Server 2008 R2 Business Intelligence, Second Edition 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.