Returning an ERRORLEVEL to DOS prompt from OSQL or SQLCMD utility

Cracked how to return a non zero exit code from a call to osql back to a dos batch file.

The answer is as follows. Note the bits in bold below are most important, and the use of the single & sign to denote running the IF ERRORLEVEL 1 command even if the previous osql command errors.

for /F %%i in ('dir *.sql /b') do osql -b -E -S MyServer\InstanceName -d MyDatabase -i %%i & IF ERRORLEVEL 1 goto ABORTBATCH

posted @ 2011-06-07 16:21  现古行  阅读(258)  评论(0编辑  收藏  举报