title: How to get the hierarchy level of this query
body: <p>I am trying to get the hierarchy level of this query. Here is the CTE recursive query</p>
  
  <pre><code>WITH CategoryRec AS 
  (
      SELECT Id, Parentid, Name
      FROM dbo.Category
  
      UNION ALL
  
      SELECT cr.Id, c.Parentid, cr.Name
      FROM CategoryRec AS cr INNER JOIN dbo.Category AS c ON cr.Parentid = c.Id
      WHERE c.Parentid IS NOT NULL
  )
  SELECT DISTINCT Id, Parentid, Name
  FROM  CategoryRec
  </code></pre>
  
  <p>This question is related to this question here: <a href="https://stackoverflow.com/questions/8483879/how-to-get-the-full-hierarchy-with-sql-cte">How to get the full Hierarchy with SQL CTE</a></p>
  
  <p>Thanks for your help</p>