title: exec xp_cmdshell bcp syntax
body: <p>I can't seem to find the right syntax to export data with column names using exec xp_cmdshell bcp in sql server management studio.I've tried the below variations</p>
  
  <pre><code>EXEC xp_cmdshell bcp "select "a_id","b_id","c_id" union select a_id,b_id,c_id from  tablename out 
  "\\network_path\a.txt" -c -Uusername -Ppassword -Sservername"
  </code></pre>
  
  <p>And </p>
  
  <pre><code>EXEC xp_cmdshell bcp 'select 'a_id','b_id','c_id' union select a_id,b_id,c_id from  tablename out 
  '\\network_path\a.txt' -c -Uusername -Ppassword -Sservername'
  </code></pre>
  
  <p>And</p>
  
  <pre><code>EXEC xp_cmdshell bcp 'select "a_id","b_id","c_id" union select a_id,b_id,c_id from  tablename out 
  "\\network_path\a.txt" -c -Uusername -Ppassword -Sservername'
  </code></pre>
  
  <p>And</p>
  
  <pre><code>EXEC xp_cmdshell bcp "select 'a_id','b_id','c_id' union select a_id,b_id,c_id from  tablename out 
  '\\network_path\a.txt' -c -Uusername -Ppassword -Sservername"
  </code></pre>
  
  <p>I have successfully used the below command to export the table,however I also need the column names.</p>
  
  <pre><code>bcp tablename out "\\network_path\a_test.txt" -c -Uusername -Ppassword -Sservername'
  </code></pre>