title: SQL Server : GROUP BY clause to get comma-separated values
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/8868604/sql-group-concat-function-in-sql-server">SQL group_concat function in SQL Server</a>  </p>
  </blockquote>
  
  
  
  <p>I am looking to create a query but somehow I am unable to do so. Can anyone please help me out here?</p>
  
  <p>The original data</p>
  
  <pre><code>ID    ReportId     Email
  1     1            a@a.com
  2     2            b@b.com
  3     1            c@c.com
  4     3            d@d.com
  5     3            e@e.com
  </code></pre>
  
  <p>I want to group by <code>ReportId</code>, but all the email should be comma separated. So the result should be:</p>
  
  <pre><code>ReportId     Email
  1            a@a.com, c@c.com
  2            b@b.com
  3            d@d.com, e@e.com
  </code></pre>
  
  <p>What is the best way to do this? </p>
  
  <p>I am trying the group by clause but if there is any other thing then i am open to implement that also. I really appreciate your time and help on this. Thank you.</p>