title: Hierarchical Data Grouping the Child and Grandchild Nodes Based on Parent Nodes in SQL Server
body: <p>I'm having the hierarchical data as shown below:</p>
  
  <pre><code>hierarchyID  hierarchylevel    Name
  0xB6               1           President
  0xB6B0             2           Manager
  0xB6B580           3           Project Head
  0xB6B5AC           4           QA LEAD
  0xB6B5AD60         5           SSE
  0xB6B5B4           4           SE
  </code></pre>
  
  <p>The hierarchical tree structure for the above data as shown below:</p>
  
  <pre><code>            President   
                  |
               Manager    
                  | 
             Project head 
                  |
         QA LEAD       SE     
            |
           SSE        
  </code></pre>
  
  <p>I am trying to display the data as shown below using SQL SERVER 2012</p>
  
  <pre><code>Level1      Level2    Level3         Level4           Data
  President                                             Manager
  President   Manager                                   Project head
  President   Manager   Project head                    QALEAD
  President   Manager   Project head                    SE
  President   Manager   Project head   QALEAD           SSE
  </code></pre>
  
  <p>Could you please help me how to write a SQL query for this.</p>