sqlcmd输出文件和屏幕输出 [英] sqlcmd with output file and screen output
本文介绍了sqlcmd输出文件和屏幕输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用sqlcmd以这种方式做一些命令行批处理(.bat):
sqlcmd -i Scripts\STEP01 .sql -o PROCESS.log -S MYSERVER -E -d MYDATABASE
我需要一个输出文件(它的工作目前)和输出trought屏幕做一些像:
@echo off
echo查询的结果是:
sqlcmd -i Scripts\STEP01.sql -o PROCESS.log -S MYSERVER -E -d MYDATABASE
pause
选择/ C:YN / M结果一致?
IF ERRORLEVEL 2 GOTO ENDWITHERROR
如果ERRORLEVEL 1 GOTO STEP2
::
- 是的,脚本工作原理suscefull,这不是问题。
- 是的,我在我的sql上有一个打印的东西。日志文件获取输出。
很多!
没有回答的类似问题:
如何使用sqlcmd运行sql脚本文件并输出到shell和文件
解决方案
我也找不到一个更好的方法,然后@Sparky建议。下面的代码添加他的建议:
@echo off
::这将执行脚本到PROCESS.log
sqlcmd -i Scripts \STEP01。 sql -o PROCESS.log -S MYSERVER -E -d MYDATABASE
::这将PROCESS.log的内容显示到屏幕
echo查询的结果是:
type PROCESS.log
pause
选择/ C:YN / M结果是否符合?
如果错误2 GOTO ENDWITHERROR
如果错误1 GOTO STEP2
I do some command line batch (.bat) with sqlcmd as this way:
sqlcmd -i Scripts\STEP01.sql -o PROCESS.log -S MYSERVER -E -d MYDATABASE
and i need an output file (it's works currently) and also the output trought the screen to do something like:
@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
Note:
- Yes, the script works suscefull, it's not an issue question.
- And yes, I've a "print "something" on my sql. The log file gets the output.
Thanks a lot!
Similar question without answer: How to run a sql script file using sqlcmd and output to both shell and file
解决方案
I also couldn't find a better way then @Sparky proposed. The following code adds his suggestion:
@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
这篇关于sqlcmd输出文件和屏幕输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文