Have an SP that will return the status of a job from the sysjobhistory table. ie.
0 = Failed
1 = Succeeded
2 = Retry
3 = Canceled
4 = In progress
All status respond correctly EXCEPT "4 = In Progress". When I run the SP, when a job is POSITIVELY running, I do not get that job returned.
If I look in the sysjobhistory table, I never see that job, or any job for that matter, with a status of 4.
My question is: Since status 4 is "In Progress", is that why it cannot show in the sysjobHISTORY file because it is not HISTORY yet?
Is there a workaround to get what I am after? Here is the main snipette of code from my SP ...
SELECT Job_ID = j.Job_ID,
Job_Status = h.Run_Status,
Run_Date = h.Run_Date,
Run_Time = h.Run_Time,
Job_Name = convert(char(80),j.Name),
Step_Name = h.Step_Name,
Comments = 'Backups are IN PROGRESS mode ... Please verify status of job' + Replace(Convert(VarChar(770),h.Message),'Executed as user: sa. ',''),
Record_Type = 'UNKNOWN',
GetDate()
FROM MSDB.dbo.SysJobHistory AS h
INNER JOIN MSDB.dbo.SysJobs AS j ON (h.Job_ID = j.Job_ID)
INNER JOIN MSDB.dbo.SysCategories AS c ON (j.Category_ID = c.Category_ID)
WHERE h.Run_Status = 4 AND
h.Run_Date >= Convert(Char(8),GetDate(),112) AND
c.Name = 'Daily Backups' AND
h.Step_ID = 1
Thanks
J. Kusch
0 = Failed
1 = Succeeded
2 = Retry
3 = Canceled
4 = In progress
All status respond correctly EXCEPT "4 = In Progress". When I run the SP, when a job is POSITIVELY running, I do not get that job returned.
If I look in the sysjobhistory table, I never see that job, or any job for that matter, with a status of 4.
My question is: Since status 4 is "In Progress", is that why it cannot show in the sysjobHISTORY file because it is not HISTORY yet?
Is there a workaround to get what I am after? Here is the main snipette of code from my SP ...
SELECT Job_ID = j.Job_ID,
Job_Status = h.Run_Status,
Run_Date = h.Run_Date,
Run_Time = h.Run_Time,
Job_Name = convert(char(80),j.Name),
Step_Name = h.Step_Name,
Comments = 'Backups are IN PROGRESS mode ... Please verify status of job' + Replace(Convert(VarChar(770),h.Message),'Executed as user: sa. ',''),
Record_Type = 'UNKNOWN',
GetDate()
FROM MSDB.dbo.SysJobHistory AS h
INNER JOIN MSDB.dbo.SysJobs AS j ON (h.Job_ID = j.Job_ID)
INNER JOIN MSDB.dbo.SysCategories AS c ON (j.Category_ID = c.Category_ID)
WHERE h.Run_Status = 4 AND
h.Run_Date >= Convert(Char(8),GetDate(),112) AND
c.Name = 'Daily Backups' AND
h.Step_ID = 1
Thanks
J. Kusch