Error Handling with Batch File & Sqlcmd

前端 未结 4 1806
傲寒
傲寒 2021-02-07 07:19

I have a batch file that runs some SELECT queries using sqlcmd, puts the results into text files, and uploads those files onto an FTP server. That\'s all working just the way it

4条回答
  •  暖寄归人
    2021-02-07 07:26

    for %%G in (*.sql) do (sqlcmd /S %sqlhost% /d %sqldbname% -E -b -i "%%G" >> output.txt if ERRORLEVEL 1 exit)
    

    Above code will loop through all the *.sql in a folder. If error encountered in any of the script , error will get logged in the output.txt file and it will stop the batch process immediately.

提交回复
热议问题