Imagine your typical manager / employee hierarchy, where you have an employee with a boss, who in turn has a boss, who in turn has a boss.
How would you write a query that would have a column with, say, all the boss's names as a varchar.
Given this data (leaving out the hierarchyid column but the id column here essentially describes that column):
id | name | bossid
1 | BigBoss | 0
2 | CTO | 1
3 | CTO Lackey | 2
4 | CIO | 1
5 | CIO Lackey | 4
End up with this resultset:
id | name | all boss names
1 | BigBoss |
2 | CTO |Big Boss
3 | CTO Lackey |Big Boss, CTO
4 | CIO |Big Boss
5 | CIO Lackey |Big Boss, CIO
Thanks!