I have created batch file for trigger SQL job using SQLCMD but we are not able to capturing the last status of job run. Please let me know what code we need to write in batch file.
As per our code we have capture only when job is run but we want status of job is failed or pass. I have tried so many thing even able to capture the log but we want only last status of job.
Below is the code using in batch file:
echo execute job
sqlcmd -S "servername" -Q "execute msd.dbo.sp_start_job @job_name='Test_Job_Autosys'" -o c:\sqlscript\output.txt
if errorlevel 1 exit/b
echo job execution completed
Output:
Job started successfully
We are not able to capture job is fail or pass; please let us know how can be capture the status of job.
sp_start_jobruns asynchronously. That is to say it starts the job then returns immediately. It does not wait for the job to finish. Please explain further what you're trying to do and we can suggest an alternate method.