runsql.bat
@echo off :start cd %cd% @echo current directory is %cd% @echo start testing @echo good example rem good sql sqlcmd -E -dmaster -Q%1 -W -b -m-1 -h-1 -s^| rem if the query or batch file abort @if %errorlevel%==1 goto b1 @if %errorlevel%==0 goto g1 :g1 rem if finished echo run example1 successful, errorlevel=%errorlevel% goto exit1 :b1 rem error message @echo run example1 failed, errorlevel=%errorlevel% goto exit1 rem exit1 :exit1 echo exit
@echo off @REM ******** ******** General Batch for Starting SQL ******** ******** @REM %1 is the name of SQL script file @rem SET SQL_NAME=%1 @SET SQL_NAME=%1 @SHIFT /1 @REM SHIFT /1 @REM P1... is parameters of SQLCMD,P1=%1... @rem c for count @set /a c=0 @rem ******** ******** parameters for sql server login ******** ******** rem @set svrName=ryemsqapaxdb1.na.avonet.net rem @set uname=batchap rem @set upwd=1qaz2WSX rem @set db=apoms @set s= %1 %2 %3 %4 %5 %6 %7 %8 %9 @FOR %%A IN (%s%) DO @set /a c=c+1 @if %c%==9 goto s9 @if %c%==8 goto s8 @if %c%==7 goto s7 @if %c%==6 goto s6 @if %c%==5 goto s5 @if %c%==4 goto s4 @if %c%==3 goto s3 @if %c%==2 goto s2 @if %c%==1 goto s1 @if %c%==0 goto s0 :s9 sqlcmd -E -dmaster -W -b -m-1 -h-1 -s^| -i %SQL_NAME% -l60 -v P1=%1 P2=%2 p3=%3 p4=%4 p5=%5 p6=%6 p=%7 p8=%8 p9=%9 @goto end :s8 sqlcmd -E -dmaster -W -b -m-1 -h-1 -s^| -i %SQL_NAME% -l60 -v P1=%1 P2=%2 p3=%3 p4=%4 p5=%5 p6=%6 p=%7 p8=%8 @goto end :s7 sqlcmd -E -dmaster -W -b -m-1 -h-1 -s^| -i %SQL_NAME% -l60 -v P1=%1 P2=%2 p3=%3 p4=%4 p5=%5 p6=%6 p=%7 @goto end :s6 sqlcmd -E -dmaster -W -b -m-1 -h-1 -s^| -i %SQL_NAME% -l60 -v P1=%1 P2=%2 p3=%3 p4=%4 p5=%5 p6=%6 @goto end :s5 sqlcmd -E -dmaster -W -b -m-1 -h-1 -s^| -i %SQL_NAME% -l60 -v P1=%1 P2=%2 p3=%3 p4=%4 p5=%5 @goto end :s4 sqlcmd -E -dmaster -W -b -m-1 -h-1 -s^| -i %SQL_NAME% -l60 -v P1=%1 P2=%2 p3=%3 p4=%4 @goto end :s3 sqlcmd -E -dmaster -W -b -m-1 -h-1 -s^| -i %SQL_NAME% -l60 -v P1=%1 P2=%2 p3=%3 @goto end :s2 sqlcmd -E -dmaster -W -b -m-1 -h-1 -s^| -i %SQL_NAME% -l60 -v P1=%1 P2=%2 @goto end :s1 sqlcmd -E -dmaster -W -b -m-1 -h-1 -s^| -i %SQL_NAME% -l60 -v P1=%1 @goto end :s0 sqlcmd -E -dmaster -W -b -m-1 -h-1 -s^| -i %SQL_NAME% -l60 @goto end :end @if %errorlevel%==1 goto bad @if %errorlevel%==0 goto good @goto exit :bad @echo file %SQL_NAME% ran failed @goto exit :good @echo file %SQL_NAME% ran successfully @goto exit :exit @echo exit
关于 sql server sqlcmd 异常捕捉 %errorlevel%
原文地址:http://blog.csdn.net/wangzhpwang/article/details/44056531