开发者

SQLCMD Usage in Batch file

开发者 https://www.devze.com 2023-01-12 15:30 出处:网络
Hi All I am Writing a Batch Script Which has to read a set of SQL Files which exi开发者_Python百科sts in a Folder then Execute Them Using SQLCMD utiliy.

Hi All I am Writing a Batch Script Which has to read a set of SQL Files which exi开发者_Python百科sts in a Folder then Execute Them Using SQLCMD utiliy.

When I am Trying to execute it does not create any output file. I am not sure where I am wrong and I am not sure how to debug the script. Can someone help me out with script?

@echo off

FOR %F IN (C:\SQLCMD*.SQL) DO sqlcmd -S LENOVO-C00 -U yam -P yam!@ -i %F -o C:\SEL.txt -p -b

IF NOT [%ERRORLEVEL%] ==[0] goto get_Error

:Success echo Finished Succesffuly exit /B 0 goto end

:get_error echo step Failed exit /B 40

:end


If this is actually in a batch file (not being executed by hand at the command line), then the %F variables need to have the % characters doubled-up because of the way that cmd.exe executes the lines read from the batch file:

FOR %%F IN (C:\SQLCMD*.SQL) DO sqlcmd -S LENOVO-C00 -U yam -P yam!@ -i %%F -o C:\SEL.txt -p -b

Though I would have thought you'd get a

F was unexpected at this time.

error if you only had one % character in front of the variable name.


Try to right click the Batch File and run as administrator.


Seems like the answer would be more like this:

FOR %%F "usebackq" IN (`dir.exe C:\SQLCMD*.SQL`) DO ... 
0

精彩评论

暂无评论...
验证码 换一张
取 消