We generate a temporary script file (e.g. from the BATCH file) which contains:DECLARE @intErrNo int EXEC @intErrNo=dbo.MySProc @Param1=xxx, @Param2=yyy:EXIT(SELECT @intErrNo)
The BATCH file contains:SQLCMD -d MyDatabase -i MyTempScript.SQL -o X:\MyPath\MyProcessName.OUT -b -l 300 -S . -E >>X:\MyPath\MyProcessName.ERRIF ERRORLEVEL 1 GOTO SQL1_ErrorECHO %DATE% %TIME% SQL MyProcessName END >>X:\MyPath\MyProcessName.ERRGOTO SQL1_DONE:SQL1_ErrorECHO %DATE% %TIME% SQL MyProcessName *** ERROR EXIT *** : %1 >>X:\MyPath\MyProcessName.ERRECHO ---------- >>X:\MyPath\MyProcessName.ERR... Some stuff here to send an EMail with the error file attached ...GOTO SQL1_DONE:SQL1_DONE... rest of batch file ...