|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, October 30, 2012 7:36 PM
Points: 148,
Visits: 69
|
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Thursday, June 06, 2013 5:01 AM
Points: 67,
Visits: 217
|
|
Hi Mohit, Regarding the latest Job status query you have posted, i have tried that but it doesn't gave me the expected result.
Here is what i have done , i have put the T-SQL in the job which will execute infinite times, so the Job Status is In Progress, but when i fired the query of the Job Status it still gives me status as successful.
Is i am going wrong somewhere , here is the query which i have used so that the Job should remain in the In Progress state. When i stop the job it does show me the Canceled status but In Progress it was not showing.
Code Snippet: declare @count int
set @count=0
while(@count<100)
print 'hi'
set @count=@count+0
Looking forward for positive response.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, November 04, 2008 10:27 AM
Points: 2,
Visits: 6
|
|
I added last run time and duration, and FQDN for msdb table to allow this to be used in a stored procedure or elsewhere than Query Analyser :D :
select distinct j.Name as "Job Name", j.description as "Job Description", h.run_date as LastStatusDate, h.run_time as LastStatusTime, h.run_duration as LastStatusDuration, case h.run_status when 0 then 'Failed' when 1 then 'Successful' when 3 then 'Cancelled' when 4 then 'In Progress' end as JobStatus from msdb..sysJobHistory h, msdb..sysJobs j where j.job_id = h.job_id and h.step_id = 1 and h.run_date = (select max(hi.run_date) from msdb..sysJobHistory hi where h.job_id = hi.job_id) and h.run_time = (select max(hj.run_time) from msdb..sysJobHistory hj where h.job_id = hj.job_id) order by 1
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, November 04, 2008 10:27 AM
Points: 2,
Visits: 6
|
|
And this, to include category information....
select distinct cat.name as "Category", j.Name as "Job Name", j.description as "Job Description", h.run_date as LastStatusDate, h.run_time as LastStatusTime, h.run_duration as LastStatusDuration, case h.run_status when 0 then 'Failed' when 1 then 'Successful' when 3 then 'Cancelled' when 4 then 'In Progress' end as JobStatus from msdb..sysJobHistory h, msdb..sysJobs j, msdb..syscategories cat where j.job_id = h.job_id and j.category_id = cat.category_id and h.step_id = 1 and h.run_date = (select max(hi.run_date) from msdb..sysJobHistory hi where h.job_id = hi.job_id) and h.run_time = (select max(hj.run_time) from msdb..sysJobHistory hj where h.job_id = hj.job_id) order by 1,3
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Friday, August 10, 2012 6:08 PM
Points: 1,156,
Visits: 801
|
|
| I found this article useful. Thanks!
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, September 20, 2012 7:11 AM
Points: 7,
Visits: 226
|
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, January 03, 2013 4:44 PM
Points: 1,336,
Visits: 595
|
|
Hi Mohit
Nice posting!
One of my DBA brought your post in my attention when he was working on finding list of jobs current status is not successful.
I happened to notice little change requirement in your query: You should replace last part using max(instance_id) that will help user to find latest status even when job ran multiple times in a day. To be precise:
syntax part:
instance_id = (select max(hi.instance_id) from msdb.dbo.sysjobhistory hi where h.job_id = hi.job_id)
Just thought and suggestion!
--www.sqlvillage.com
|
|
|
|