I have two tables, one stores a techtree and has the following structure:
**TECHTREE TABLE**
ID - int
ParentID - int (relational to ID)
name - varchar
and a datatable 'UserSkills' with the following structure:
**USERSKILLS TABLE**
TECHID - int (relational to TECHTREE.ID)
SKILLLEVEL - varchar
LOGIN - varchar
Given is the following techtree data
ID ParentID Name
1 24 Microsoft
2 1 Server
3 1 Hyper-V
4 24 VMWare
5 4 vSphere
7 2 Betriebssystem
8 2 AD, DNS, DHCP
9 2 PKI
14 5 4.x
15 5 5.x
16 4 VDI/View
17 4 SRM
18 24 Symantec
19 18 Backup Exec
20 19 2010
21 19 2012
22 18 SEP
23 24 Citrix
24 NULL Data Center SW
25 NULL Data Center HW
26 NULL IPT
27 NULL Networking
28 NULL Security
29 NULL Misc
and following userskills data
TechID SkillLevel Login
7 Expert mike
8 Basics mike
9 Basics peter
67 Expert peter
31 Expert peter
32 Support chris
33 Expert peter
34 Expert chris
35 Expert adam
36 Support adam
65 Support adam
66 Expert tom
78 Expert tom
75 Basics tom
76 Expert tom
77 Expert tom
Now i want to get the rows from userskill table including the full hierarchy from the techtree table. The result should look like
ID LVL0 LVL1 LVL2 LVL3 LVL4 LVL5 LVL6 Skilllevel
7 Data Center SW Microsoft Server OS Expert
8 Data Center SW Microsoft Server AD, DNS, DHCP Basics
9 Data Center SW Microsoft Server PKI Basics
67 Networking Expert
31 Networking Expert
Does anybody knows how this can be achieved in sql?