title: Tree structure in tsql - How get data by the special class in branches
body: <p>I have structure like that(as example):</p>
  
  <pre><code>ID    ClassId   Name         Parent
  --------------------------------------
  1      12      Boss       
  2      13      Manager1         1
  3      13      Manager2         1
  4      13      Manager3         1
  5      14      SubManager1      3
  6      15      UnderSubManager1 5
  7      16      Worker1          2
  8      16      Worker2          6
  9      14      SubManager2      4
  10     16      Worker3          9
  </code></pre>
  
  <p>Than, we have this:</p>
  
  <pre><code>Boss-&gt;Manager1-&gt;Worker1
  Boss-&gt;Manager2-&gt;SubManager1-&gt;UnderSubManager1-&gt;Worker2
  Boss-&gt;Manager3-&gt;SubManager2-&gt;Worker3
  </code></pre>
  
  <p>I need query, that give me a this reult:</p>
  
  <pre><code>Boss-&gt;Manager1-&gt;worker1
  Boss-&gt;Manager2-&gt;worker2
  Boss-&gt;Manager3-&gt;worker3
  </code></pre>
  
  <p>I try do this witch CTE using ClassId but with poor result :(</p>