SQLTeam.com | Weblogs | Forums

Look at SQL Job Agent using SQL script not GUI

Can somebody please help, how do you look at job history(SQL job agent) using sql script?

hi

you can query tables ... !!! please take a look .. TSQL Scripting !!!

1 Like

You can try the query below.

select jobs.name,hist.message,
case when Hist.Run_Status=1 then 'Successful' else 'Failed'
end as 'RUN_STATUS',
left(cast(hist.run_date as varchar),4)+'-'+
substring(cast(hist.run_date as varchar),5,2)+'-'+
substring(cast(hist.run_date as varchar),7,2) Run_date,Run_Time,
case when run_duration>60 then convert(varchar,run_duration/60) + ' minutes' else
convert(varchar,run_duration) + ' seconds' end as Run_Duration
from msdb.dbo.sysjobhistory Hist
inner join msdb.dbo.sysjobs Jobs
on hist.job_Id=jobs.job_id

1 Like