debugsqlCritical
How to make sqlcmd return an ERRORLEVEL other than 0 when the .sql script fails?
Viewed 0 times
scriptthefailserrorlevelreturnsqlthanmakesqlcmdhow
Problem
I'm running sqlcmd from a batch file and I was wondering how to make it return an ERRORLEVEL other than 0 when something goes wrong with the backup.
Solution
You should use the option -b in sqlcmd.
-b
Specifies that sqlcmd exits and returns a DOS ERRORLEVEL value when an error occurs. The value that is returned to the DOS ERRORLEVEL variable is 1 when the SQL Server error message has a severity level greater than 10; otherwise, the value returned is 0
http://msdn.microsoft.com/en-us/library/ms162773.aspx
-b
Specifies that sqlcmd exits and returns a DOS ERRORLEVEL value when an error occurs. The value that is returned to the DOS ERRORLEVEL variable is 1 when the SQL Server error message has a severity level greater than 10; otherwise, the value returned is 0
http://msdn.microsoft.com/en-us/library/ms162773.aspx
Context
StackExchange Database Administrators Q#77298, answer score: 70
Revisions (0)
No revisions yet.