title: Concatenating a column within the same column in SQL Server
body: <p>Hi so I have a question on concatenating a column. I have two tables. </p>
  
  <pre><code>Table 1: Sales Order-&gt; OrderID, ProductsOnHold (Should list product(s) on hold)
  Table 2: Products-&gt; ProductID, OnHold (boolean)
  </code></pre>
  
  <ul>
  <li>A Sales Order can have many products.</li>
  <li>A product can have a hold, which would make the Sales Order be put on hold if that order has that product.</li>
  <li><p>So a sale order can be on hold for have 1 or more products on hold. </p>
  
  <p>I was able to get one product to display if the order is on hold, 
  but what if it has more products on hold - 
  how could I display them as well? 
  This is for a view I am creating.</p></li>
  </ul>
  
  <p>This is what I have done so far:</p>
  
  <pre><code>(SELECT ProductName
   FROM Products with (NOLOCK)
   WHERE (OnHold = 1) AND (EXISTS   
      (SELECT CASE
                 WHEN (COUNT(DISTINCT Product)&gt; 1) THEN (Product + ', ' + Product)
                 ELSE Product END AS ProductName
       FROM  SalesOrder WITH (NOLOCK) 
       GROUP BY OrderID ))) AS ProductsOnHold
  </code></pre>
  
  <p>Desired Output:</p>
  
  <pre><code>OrderID | ProductsOnHold
  ----------------------------------
      1   | P1, P2, P7                      
      2   |                
      3   | P1            
      4   | P1, P7, P8, P9, P15, P77
  </code></pre>
  
  <p>Anything I am missing in my sql query?</p>