title: BCP - Export CSV with header
body: <p>I have run the following query to export my Ms SQL table as CSV. It working good. Now I want to add the field name as the first row. How is it possible?</p>
  
  <pre><code>declare @sql varchar(8000)
  select @sql = 'bcp "select * from test_table" queryout C:\Test_SP\Tom.csv -c -t, -T -S' + @@servername
  exec master..xp_cmdshell @sql
  </code></pre>
  
  <p>I know that I can specify the names @Red Devil answered. But the table is dynamic, Its fields are not fixed, It will change. I am trying to find a method to fetch the field names from the table definition and prepend it into the result CSV</p>