title: Exporting CSV data using SQLCMD.EXE
body: <p>I'm trying to export data from SQL Server into CSV format. I have a bat task to do this that's run at regular intervals. Command is:</p>
  
  <pre><code>SQLCMD.EXE -d [db details] -i c:\export.sql -o c:\export.csv -s"," -W 
  </code></pre>
  
  <p>The SQL file is just a SELECT * from a view. </p>
  
  <p>This works except that some of the rows have commas in the data, so the values need to be quoted. I could change the column separator to be "','", but then I'd need SQL Server to escape single quotes in the data as well. </p>
  
  <p>Unfortunately changing the separator to another character is unlikely to solve the problem in 100% of cases as one of the fields contains serialized data from another application which contains all sorts of weird and wonderful characters.</p>
  
  <p>Is there any way for me to get standard, quoted CSV data?</p>