如何将目录中的每个文件作为参数调用存储过程?
How do I call a stored procedure on each of the files in a directory as a parameter?
我对批处理脚本非常陌生,但由于我的客户不允许使用 SSIS,这是我现在唯一可以求助的工具...
我有一个平面文件文件夹,我想对每个文件调用一个存储过程。
我可以遍历文件,也可以调用 sqlcmd,但我不知道如何将文件名传递给存储过程。
这是我的:
pushd D:\test
for /F "delims=" %%i IN ('dir /b') do sqlcmd -S servername -U username -P pword -Q "EXEC db.schema.sp $(the_filename)" -v the_filename = %%i
popd
但是我收到一个错误:
“%”
附近的语法不正确
正确的语法是什么?
试试这个:
pushd D:\test
for /F "delims=" %%i IN ('dir /b') do (
sqlcmd -S servername -U username -P pword -Q "EXEC db.schema.sp '%%i'"
)
popd
括号不是必需的,但我喜欢使用它们来增加清晰度。
我对批处理脚本非常陌生,但由于我的客户不允许使用 SSIS,这是我现在唯一可以求助的工具...
我有一个平面文件文件夹,我想对每个文件调用一个存储过程。
我可以遍历文件,也可以调用 sqlcmd,但我不知道如何将文件名传递给存储过程。
这是我的:
pushd D:\test
for /F "delims=" %%i IN ('dir /b') do sqlcmd -S servername -U username -P pword -Q "EXEC db.schema.sp $(the_filename)" -v the_filename = %%i
popd
但是我收到一个错误: “%”
附近的语法不正确正确的语法是什么?
试试这个:
pushd D:\test
for /F "delims=" %%i IN ('dir /b') do (
sqlcmd -S servername -U username -P pword -Q "EXEC db.schema.sp '%%i'"
)
popd
括号不是必需的,但我喜欢使用它们来增加清晰度。