[英]Using for loop bat file windows for multiple command calls
I want to export all data from sql server table to a csv, I know I can get the desired result by: 我想将所有数据从sql server表导出到csv,我知道我可以通过以下方式获得所需的结果:
sqlcmd -S . -d database -E -s, -W -Q "SELECT * FROM TABLENAME" > file.csv
I have many tables, so I want to create a .bat file that do the work for me, I have this: 我有很多表,所以我想创建一个.bat文件来为我完成工作,我有这个:
set "list = A B C D"
for %%x in (%list%) do (
sqlcmd -S . -d database -E -s, -W -Q "SELECT * FROM %%x" > %%x.csv
)
But I am getting errors I don't know (I am not an expert in bat files). 但是我遇到了我不知道的错误(我不是bat文件的专家)。 Why this does not work?
为什么这不起作用? How can I do what I want?
我该怎么办?
Spacing is important when using set
(unless you're doing math with the /A
switch). 使用
set
时,间距很重要(除非使用/A
开关进行数学运算)。 As written, the variable you're setting isn't %list%
. 按照书面规定,您要设置的变量不是
%list%
。 It's %list %
. 这是
%list %
。 Change your set
command as follows: 更改您的
set
命令,如下所示:
set "list=A B C D"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.