Mar 11, 2008

SQLSerer 2000 : Job History

This SQL return the job history of SQLServer Agent in yesterday.

SELECT
  JobHistroy.run_status,
  Jobs.name,
  JobHistroy.step_id,
  JobHistroy.step_name,
  JobHistroy.message,
  JobHistroy.run_date,
  JobHistroy.run_time,
  JobHistroy.server
FROM
  msdb.dbo.sysjobs Jobs

    INNER JOIN
      msdb.dbo.sysjobhistory JobHistroy
      ON
        Jobs.job_id = JobHistroy.job_id
WHERE
  run_date = CAST(
      CAST(YEAR(GETDATE()-1) AS CHAR(4)) +
      RIGHT('00' + CAST(MONTH(GETDATE()-1) AS VARCHAR(2)),2) +
      RIGHT('00' + CAST(DAY(GETDATE()-1) AS VARCHAR(2)),2)
             AS INT) and
  step_id = 0
order by
  jobs.name

No comments: