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.
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.