title: Trying to create a batch file exporting using 'sqlcmd' to a CSV
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/425379/how-to-export-data-as-csv-format-from-sql-server-using-sqlcmd">How to export data as CSV format from SQL Server using sqlcmd?</a>  </p>
  </blockquote>
  
  
  
  <p>I'm trying to create a .bat file to query from a database using <code>sqlcmd</code>. This is what I got so far using sources online:</p>
  
  <pre><code>sqlcmd -S servername\sqlexpress -d DNAME -U username -P password
  -Q "SELECT 1,2,3,4,5
      FROM table1
      SELECT 6,7,8,9,10
      FROM table2
      BACKUP DATABASE [DNAME] TO DISK = 'C:\test.csv'"
  </code></pre>
  
  <p>If I run this at its current state the CSV file isn't being created.</p>