title: Want to insert multiple value in column of SQL table separated by Comma ,
body: <p>I want to add multiple UCId s in single column of SQL Server. I am using <code>Stuff</code> but result is showing all the UC id instead of condition.</p>
  
  <p>Table:</p>
  
  <pre><code>UCId    UCPre                           UCPost                          UCNext (No column name)
  -----------------------------------------------------------------------------------------------
  UC01    User must be Registerd          User is Loggined sucessfully    UC02    UC03,UC05,UC02
  UC02    User is Loggined sucessfully    User is added                   UC03    UC03,UC05,UC02
  UC03    File must be selected           File is added                   NULL    UC03,UC05,UC02
  UC04    File is added                   File is deleted                 NULL    UC03,UC05,UC02
  UC05    User is Loggined sucessfully    User is deleted                 NULL    UC03,UC05,UC02
  </code></pre>
  
  <p>I am using following query:</p>
  
  <pre><code>SELECT 
      b.*,
      STUFF(
            (SELECT ',' + a.UCId 
             FROM UCDetails a, test b 
             WHERE (b.UCPost = a.UCPre)
             FOR XML PATH ('')),1,1,'') 
  FROM 
      test b 
  JOIN
      UCDetails a ON b.UCPost = a.UCPre
  </code></pre>
  
  <p>What I want:</p>
  
  <p>I want in <code>UCNext</code> column of UC01 Id of UC02 and UC05 separated by commas (<code>UC02,UC05</code>) as the UCPost of UC01 is matched with UCPre of UC02 and UC05.</p>