title: Sql query for tree table
body: <p>I have a table with tree structure:</p>
  
  <pre><code>id parentId name
  ----------------
  1  0        Category1
  2  0        Category2
  3  1        Category3
  4  2        Category4
  5  1        Category5
  6  2        Category6
  7  3        Category7
  </code></pre>
  
  <p>In sql query resut I need a table like:</p>
  
  <pre><code>id parentId level name
  ----------------------
  1  0        0     Category1
  3  1        1     Category3
  7  3        2     Category7
  5  1        1     Category5
  2  0        0     Category2
  4  2        1     Category4
  6  2        1     Category6
  </code></pre>
  
  <p>Who can help me to write ms-sql query? 
  Thanks!</p>