Using the following sqlcmd script:
sqlcmd -S . -d MyDb -E -s, -W -Q \"select account,rptmonth, thename from theTable\"
> c:\\dataExport.csv
<
In addition, if you want to query out all records in a table, you can code as
Assign the above queries into a variable %query%. The the command will be looks like as below.
SQLCMD -h -1 -W -E -S %sql_server% -d %sql_dabase% -Q %query% -s"," -o output_file.csv