title: how to concatenate multiple rows into one
body: <p>Using SQL 2008 R2
  I have two tables and want to create a table like:</p>
  <p><a href="https://i.stack.imgur.com/uI6mR.png" rel="nofollow noreferrer">output</a></p>
  <p>Input tables
  <a href="https://i.stack.imgur.com/WpkFg.png" rel="nofollow noreferrer">input table 1</a></p>
  <p><a href="https://i.stack.imgur.com/hqa3m.png" rel="nofollow noreferrer">inout table 2</a></p>
  <p>I have tried using stuff function as</p>
  <pre><code>SELECT o.DEPT_ID,o.CLIENT_ID,
         code,
         (STUFF((SELECT CAST(', ' + CODE AS VARCHAR(MAX)) 
           FROM ORDERS
           WHERE (o.FUNDER_ID = f.FUNDER_ID) 
           FOR XML PATH ('')), 1, 2, '')) AS funder_code
  FROM FUNDERS f
  join ORDERS o on o.FUNDER_ID=f.FUNDER_ID 
  where o.DEPT_ID=111 and CLIENT_ID='B001'
  </code></pre>
  <p>and I'm not getting the output.</p>