Adding Data to the Table

Next, you will add five employees to the EmployeeHierarchy table. The employees (and their positions within the company) will be named Jodi (CEO), Jim (CFO), Kay (COO), Bob (Manager), and Andy (Manager). To accomplish this, enter and execute the following code:

Declare @CEO HierarchyID,   @COO HierarchyID,   @CLevel HierarchyID; Select  @CEO = HierarchyID::GetRoot(); Insert Into dbo.EmployeeHierarchy (Name, Position, OrganizationLevel) Values ('Jodi','CEO', @CEO),   ('Jim','CFO', @CEO.GetDescendant(Null,Null)); Select @CLevel =MAX(OrganizationLevel) From dbo.EmployeeHierarchy Where OrganizationLevel.GetAncestor(1)= @CEO; Insert Into dbo.EmployeeHierarchy (Name, Position, OrganizationLevel) Values ('Kay','COO', ...

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.