bisonn Dec 9th, 2019 220 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. select Name, js.step_id Step, js.command Source, j.enabled Enabled, convert(char(16), date_created, 120) Created, convert(char(16), date_modified, 120) Modified,
  2. case jh.run_status when 0 then 'Failed' when 1 then 'Success' when 2 then 'Retry' when 3 then 'Canceled' when 4 then 'In progress' end LastStatus,
  3. convert(char(16),cast(stuff(stuff(cast(jh.run_date as varchar),7,0,'-'),5,0,'-') + ' ' + stuff(stuff(replace(str(jh.run_time,6,0),' ','0'),5,0,':'),3,0,':') as datetime),120) as LastRun,
  4. j.job_id
  5. from msdb..sysjobs j
  6. join msdb..sysjobsteps js on js.job_id = j.job_id
  7. outer apply (
  8.     select top 1 instance_id, jh.run_status, jh.run_date, jh.run_time from msdb..sysjobhistory jh
  9.     where jh.job_id=j.job_id and jh.step_id=0
  10.     order by instance_id desc
  11. ) jh
  12. where 1=1
  13. and js.command like N'%xxxxxxxxxxxxxxxxx%'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand