title: Concatenate SQL columns with comma separated
body: <p>Is there any alternate way to concatenate SQL columns with comma separated. I am using below logic for concatenation. The columns (col1,col2,col3) can have <strong>null</strong> values.</p>
  <pre><code>select 
  stuff(
          left(concat(col1,',',col2,',',col3),
              len(concat(col1,',',col2,',',col3)) -
          patindex('%[^,]%',reverse(concat(col1,',',col2,',',col3)))+1
              )
          ,1,
          patindex('%[^,]%',concat(col1,',',col2,',',col3))-1,''
      )
  from mytable
  </code></pre>
  <ul>
  <li>Sample data/output</li>
  </ul>
  <p><a href="https://i.stack.imgur.com/CvMvC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CvMvC.png" alt="enter image description here" /></a></p>