我的文件夹中有以下文件:
Script1.sql
Script2.sql
Script3.sql
以下命令成功执行每个脚本:
@echo off
set /p sname= Please enter the servername:
set /p dbname= Please enter the databasename:
ECHO started the batch process at %TIME% >output.txt
for %%f in (*.sql) do (
sqlcmd.exe -S %sname% -d %dbname% -i %%f >>output.txt
%~f0"
)
pause
结果
(1 rows affected)
(3 rows affected)
(2 rows affected)
我想知道的是如何在每个文件执行后输入文件名,并将此名称存储在output.txt文件中,即
(1 rows affected)
Script1.sql
(3 rows affected)
Script2.sql
(2 rows affected)
Script3.sql
任何帮助表示赞赏
答案 0 :(得分:4)
只输出文件名,问题是什么?
for %%f in (*.sql) do (
echo %%~nf >> output.txt
sqlcmd.exe -S %sname% -d %dbname% -i %%f >>output.txt
)