title: Merge data many rows of one column into a single row in sql server
body: <p>I have a table like</p>
  
  <pre><code>create table temp_table (col1 int)
  </code></pre>
  
  <p>I have some data in this table like</p>
  
  <pre><code>insert into temp_table 
  values(1), (2), (3), (4)
  </code></pre>
  
  <p>Now I want the data to be output as follows:</p>
  
  <pre><code>1,2,3,4
  </code></pre>
  
  <p>I have used the query:</p>
  
  <pre><code>select cast(col1 as nvarchar)+',' 
  from temp_table 
  for xml path('')
  </code></pre>
  
  <p>The problem is that the output comes in XML format and i need it in simple text/string format. I tried searching for transpose but <code>FOR XML()</code> was mentioned everywhere and it didn't helped me.</p>
  
  <p>Any suggestions?</p>