views:

42

answers:

1

hi everybody, i am fresher in SQL,i want write a query to get the last 24 hour jobs record from msdb.dbo.sysjobhistory,but i cant get because,here i get the run_date and run_time as like the number.how i will convert the run_date and run_time into datetime and get the last 24 hour job record.

i am using SQL Server 2000

thanks in advance

+1  A: 

Check out this post - it shows how to "decode" those run_date columns from sysjobhistory.

You should be able to get the entries from the last 24 hours with a query something like this:

SELECT 
    j.name as JobName, 
    LastRunDateTime = 
    CONVERT(DATETIME, CONVERT(CHAR(8), run_date, 112) + ' ' 
    + STUFF(STUFF(RIGHT('000000' + CONVERT(VARCHAR(8), run_time), 6), 5, 0, ':'), 3, 0, ':'), 121)
FROM 
    msdb..sysjobs j
INNER JOIN
    msdb..sysjobhistory jh ON j.job_id = jh.job_id
WHERE
    CONVERT(DATETIME, CONVERT(CHAR(8), run_date, 112) + ' ' 
    + STUFF(STUFF(RIGHT('000000' + CONVERT(VARCHAR(8), run_time), 6), 5, 0, ':'), 3, 0, ':'), 121) > DATEADD(HOUR, -24, GETDATE())
marc_s
Hi,thanks for replys.actually i m executing the folloing query::select sysjobs.job_id,sysjobs.name,sysjobhistory.step_name,sysjobhistory.message,sysjobhistory.run_status,sysjobhistory.run_date,sysjobhistory.run_time,sysjobhistory.run_duration,sysjobs.date_created,sysjobs.date_modified,sysjobs.version_number from sysjobhistory Inner join sysjobs on sysjobhistory.job_id=sysjobs.job_idhow i can get record according to datetime filter
gofor.net
thanks "marc_s" its work perfectly....thanks again
gofor.net