title: SQL Server - Concatenate all child IDs into delimited string in parent record
body: <p>I've a question about a hierarchical (adjacency model) SQL Server table. This link <a href="https://stackoverflow.com/questions/10446424/get-child-records-on-one-column">Get child records on one column</a> shows how to populate a parent field with a concatenated list of all child records. So the "Children" column in my table becomes:</p>
  
  <pre><code>ID ParentID Name   Children
  1  NULL     Root   2,3
  2  1        L2-1   4
  3  1        L2-3   NULL
  4  2        L3-4   6
  5  3        L3-5   NULL
  6  4        L4-6   NULL
  </code></pre>
  
  <p>Could someone advise how I could do this for multiple levels i.e. all descendants, not just the immediate children?</p>
  
  <p>i.e. I'd like the table to be:</p>
  
  <pre><code>ID ParentID Name   Children
  1  NULL     Root   2,3,4,5,6
  2  1        L2-1   4,6
  3  1        L2-3   5
  4  2        L3-4   6
  5  3        L3-5   NULL
  6  4        L4-6   NULL
  </code></pre>
  
  <p>Thanks!</p>