I want to export all data from sql server table to a csv, I know I can get the desired result by:
sqlcmd -S . -d database -E -s, -W -Q "SELECT * FROM TABLENAME" > file.csv
set "list = A B C D"
for %%x in (%list%) do (
sqlcmd -S . -d database -E -s, -W -Q "SELECT * FROM %%x" > %%x.csv
Spacing is important when using
set (unless you're doing math with the
/A switch). As written, the variable you're setting isn't
%list %. Change your
set command as follows:
set "list=A B C D"