title: SQL Server String Concat with Stuff
body: <p>I've looked online a few days now to how to use STUFF on sql server, most of the examples I see are involving only two tables and my query is going through 3 tables and I just can't get it to work here is the query without the STUFF function which gets me all the data I want :</p>
  
  <pre><code>select c.category_name,r.role_name
  from categories as c 
  join role_categ as rc on c.category_id=rc.category_id 
  join roles as r on r.role_id=rc.role_id
  where rc.c_read='1';
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/SOyif.png" alt="These are the results"></p>
  
  <p>What I want is where you have a Category_name then Id want all the role_names in one cell in row one ex: </p>
  
  <pre>
  BCM-Télécopieur-photocopieur Admin,Administation
  </pre>
  
  <p>Here what I have with the stuff function but doesnt work jsut gives me the same table as the other query</p>
  
  <pre><code>select c.category_name,STUFF((
      select ','+r.role_name
      from roles as r
      where rc.role_id=r.role_id
      for xml path('')),1,1,'')
  from role_categ as rc
  join categories as c on c.category_id=rc.category_id
  </code></pre>
  
  <p>Any help would be appreciated.</p>