我这样用sqlcmd做一些命令行批处理(.bat):
sqlcmd -i Scripts\STEP01.sql -o PROCESS.log -S MYSERVER -E -d MYDATABASE
而且我需要一个输出文件(当前可用),并且输出也需要在屏幕上执行以下操作:
@echo off echo The result of the query was: sqlcmd -i Scripts\STEP01.sql -o PROCESS.log -S MYSERVER -E -d MYDATABASE pause CHOICE /C:YN /M "Is the result accord?" IF ERRORLEVEL 2 GOTO ENDWITHERROR IF ERRORLEVEL 1 GOTO STEP2
注意事项 :
非常感谢!
我也找不到@Sparky建议的更好的方法。以下代码添加了他的建议:
@echo off :: this will execute the script into PROCESS.log sqlcmd -i Scripts\STEP01.sql -o PROCESS.log -S MYSERVER -E -d MYDATABASE :: this present the contents of PROCESS.log to the screen echo The result of the query was: type PROCESS.log pause CHOICE /C:YN /M "Is the result accord?" IF ERRORLEVEL 2 GOTO ENDWITHERROR IF ERRORLEVEL 1 GOTO STEP2