For use within SQL queries, how do folks evaluate the total run time of jobs in the QUEUEDJOB table, since the STARTTIME & STOPTIME fields are formatted as (decimal(6,0),not null), instead of date/time format?
We are trying to write a query to identify "long-running" jobs, in the active job queue by comparing the STARTTIME to GETDATE() tme stamp, but not sure how to convert the STARTDATE formatting in order to be able to successfully compare the two.
Any advice would be appreciated. Thank you in advance.
You are welcome!
Glad I was able to help out.
In case anyone is interested in an Oracle solution to this issue. The first trick is to convert the DATE and TIME columns to character strings, concatenate them, then convert them back to dates before subtracting them to get the duration. I had this part a few years ago. The problem was converting the result back to a character string that had just the hours, minutes, seconds. I received various errors depending on what I tried. I then found an example on the Internet where the 'Epoch time' of Jan 1 1970 was added to the difference. Since Oracle stores DATE datatypes as the number of seconds since epoch, adding that date is essentially adding zero. However, this seems to perform an implicit converstion of the result to the character format used for the epoch value. Just make sure that its time portion contains the format that you want in your final result. Greg's solution uses the MSSQL Date style of 114. If you want fractional seconds like it has, in Oracle you will need to convert to TIMESTAMP vs DATE. SELECT USERNAME, JOBNAME, TOKEN, ACTSTARTDATE, ACTSTARTTIME, STOPDATE, STOPTIME, to_char( to_date('1970-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss' + ( to_date(to_char(STOPDATE,'mmddyyyy'||to_char(STOPTIME,'099999','mmddyyyyhh24miss' - to_date(to_char(ACTSTARTDATE,'mmddyyyy'||(to_char(ACTSTARTTIME,'099999' ),'mmddyyyyhh24miss' ) ,'hh24:mi:ss' as "RunTime Duration" from gen.queuedjob --your optional WHERE clause here order by actstartdate desc ;