0

Possible Duplicate:
How to export data as CSV format from SQL Server using sqlcmd?

I'm trying to create a .bat file to query from a database using sqlcmd. This is what I got so far using sources online:

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'"

If I run this at its current state the CSV file isn't being created.

Community
  • 1
  • 1
ZLeOLT
  • 3
  • 3

1 Answers1

0

Batch files do not have free whitespace, so you cannot just insert line breaks where you want. Put all the code in a single line instead.

Joey
  • 344,408
  • 85
  • 689
  • 683
  • I have removed the spaces however it still does not create a csv file. I'm very new to batch files and sqlcmd's as I just started but I appricate the help I have recieved – ZLeOLT Jul 03 '12 at 13:18