Return value of SQLCMD

百般思念 提交于 2019-11-30 18:09:59

You need to use the -V option.

Example:

  > SQLCMD.EXE -S whatever -E -V16 -Q "USE does_not_exist"
  Msg 911, Level 16, State 1, ...
  Could not locate entry ...
  > echo %ERRORLEVEL%
  16

Update: Alternatively you can use the -b option. Which has different semantics to the execution (the whole batch stops on the first error). YMMV.

Example:

  > SQLCMD.EXE -S whatever -E -b -Q "USE does_not_exist"
  Msg 911, Level 16, State 1, ...
  Could not locate entry ...
  > echo %ERRORLEVEL%
  1

You can also combine -b and -V.

I am not sure, but did you tried SQLCMD -m switch? sqlcmd Utility

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!