I use SQL Server 2000.
Suppose I have two tables like the following:
Area
----------------------------------
ID| Name | HierarchyLevel
----------------------------------
1 | World | 1
2 | America| 2
3 | Europe | 2
4 | Africa | 2
5 | USA | 3
and
AreaHierarchy
------------------------
ID | ParentID | ChildID
------------------------
1 | 1 | 2
2 | 1 | 3
3 | 1 | 4
4 | 2 | 5
where
AreaHierarchy.ParentID and AreaHierarchy.ChildID are FKs of Area.ID
How can I find the nth parent of USA?
Is it possible without looping?
Probably not.