I created a batch file to run an SQL job using SQLCMD, but we cannot capture the last status of the job. Please let me know what code we need to write in the batch file.
According to our code, we only have a capture when completing a task, but we want the status of the task to fail or pass. I tried so many things, even those that can capture a magazine, but we only want the latest job status.
The following is the code used in the batch file:
echo execute job sqlcmd -S "servername" -Q "execute msd.dbo.sp_start_job @job_name='Test_Job_Autosys'" -oc:\sqlscript\output.txt if errorlevel 1 exit/b echo job execution completed
Output:
Job started successfully
We can not complete the task, we will not receive or miss; tell us how you can fix the status of the work.
source share