Looking for a way to flatten the Department Tree
We're looking for a way to flatten out our GL Department tree, so that it could be contained within a single table where each row represents a department and contains the recursive parent department info for that department.
For example, if the department structure looked like below:
- Departments
- Sales
- International
- Regional
The table/query would return something like the below:
Department, Description, Parent1, Parent2, Parent3, Parent4
0001, Departments, NULL, NULL, NULL, NULL
0100, Sales, 0001, NULL, NULL, NULL, NULL
1001, International, 0001, 0100, NULL, NULL
1002, Regional, 0001, 0100, NULL, NULL
Has anyone done this? Is there a delivered query or table that already does this?