I am using below batch script to trigger the Job ABC.Job ABC is failed but the if statement is not working.It should go to ErrorHandler block but it is going to.:Done block.Any help will be appreciated.
cd C:\Program Files\Microsoft SQL Server\110\Tools\Binn
sqlcmd -S xxxxxx -U xxxxxx -P xxxxxx -b -Q "DECLARE @flag int; EXEC @flag = msdb.dbo.sp_start_job N'ABC'; IF @flag = 1 BEGIN select 'failure'; END ELSE BEGIN PRINT 'success'; END;"
IF %ERRORLEVEL% == 0 GOTO Done
GOTO ErrorHandler
ECHO SQLCMD returned a zero exit code
:ErrorHandler
ECHO SQLCMD returned an error
:Done
cd C:\Program Files\Microsoft SQL Server\110\Tools\Binn
sqlcmd -S xxxxxx -U xxxxxx -P xxxxxx -b -Q "DECLARE @flag int; EXEC @flag = msdb.dbo.sp_start_job N'ABC'; IF @flag = 1 BEGIN select 'failure'; END ELSE BEGIN PRINT 'success'; END;"
IF %ERRORLEVEL% == 0 GOTO Done
GOTO ErrorHandler
ECHO SQLCMD returned a zero exit code
:ErrorHandler
ECHO SQLCMD returned an error
:Done