Long Running Jobs based on average time of last 5 run

Hi Experts,
I need a query to find out the Long Running Jobs, based on average time of last 5 run.
Could you please help me.
Thanks in advance. 
--------------------------------- Devender Bijania

SELECT 
    [sJOB].[name] AS [JobName]
    , CASE 
        WHEN [sJOBH].[run_date] IS NULL OR [sJOBH].[run_time] IS NULL THEN NULL
        ELSE CAST(
                CAST([sJOBH].[run_date] AS CHAR(8))
                + ' ' 
                + STUFF(
                    STUFF(RIGHT('000000' + CAST([sJOBH].[run_time] AS VARCHAR(6)),  6)
                        , 3, 0, ':')
                    , 6, 0, ':')
                AS DATETIME)
      END AS [LastRunDateTime]
    , CASE [sJOBH].[run_status]
        WHEN 0 THEN 'Failed'
        WHEN 1 THEN 'Succeeded'
        WHEN 2 THEN 'Retry'
        WHEN 3 THEN 'Canceled'
        WHEN 4 THEN 'Running' -- In Progress
      END AS [LastRunStatus]
    , STUFF(
            STUFF(RIGHT('000000' + CAST([sJOBH].[run_duration] AS VARCHAR(6)),  6)
                , 3, 0, ':')
            , 6, 0, ':') 
        AS [LastRunDuration (HH:MM:SS)]
      , CASE [sJOBSCH].[NextRunDate]
        WHEN 0 THEN NULL
        ELSE CAST(
                CAST([sJOBSCH].[NextRunDate] AS CHAR(8))
                + ' ' 
                + STUFF(
                    STUFF(RIGHT('000000' + CAST([sJOBSCH].[NextRunTime] AS VARCHAR(6)),  6)
                        , 3, 0, ':')
                    , 6, 0, ':')
                AS DATETIME)
      END AS [NextRunDateTime]
FROM 
    [msdb].[dbo].[sysjobs] AS [sJOB]
    LEFT JOIN (
                SELECT
                    [job_id]
                    , MIN([next_run_date]) AS [NextRunDate]
                    , MIN([next_run_time]) AS [NextRunTime]
                FROM [msdb].[dbo].[sysjobschedules]
                GROUP BY [job_id]
            ) AS [sJOBSCH]
        ON [sJOB].[job_id] = [sJOBSCH].[job_id]
    LEFT JOIN (
                SELECT 
                    [job_id]
                    , [run_date]
                    , [run_time]
                    , [run_status]
                    , [run_duration]
                    , [message]
                    , ROW_NUMBER() OVER (
                                            PARTITION BY [job_id] 
                                            ORDER BY [run_date] DESC, [run_time] DESC
                      ) AS RowNumber
                FROM [msdb].[dbo].[sysjobhistory]
                WHERE [step_id] = 0
            ) AS [sJOBH]
        ON [sJOB].[job_id] = [sJOBH].[job_id]
        AND [sJOBH].[RowNumber] = 1
ORDER BY [LastRunDateTime] desc,
         [LastRunDuration (HH:MM:SS)] DESC
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence

Similar Messages

  • Regarding Running job for so much time

    Hi all,
      I have a zprogram which is executing aroung 15000 sec , when i  run with the  same varient in th other time it is getting finished in 4000 sec, what would be the reason behind this ...
    Please suggest me some thing on this..
    and also tell me how the stats will help me to solve this problem
    Thanks,
    Suresh

    Hi Frd
    In Ur Program u may using LOOPING ...this may take long time for execute the program and while giving some varient ,it will select corresponding values in select statement and reduces the LOOPING time.
    Change u logic ,it will reduce ur execution time.
    Reward Me Point
    By
    Pari

  • Identify Jobs that are not running on their Scheduled date time

    I have 29 scheduled jobs that run at different intervals of time. Some run once a day. few others run on hourly basis while others run on Sundays.
    I was working on a query that would let me know if a particular job did not run on its scheduled date and time.
    SELECT * from all_scheduler_jobs WHERE state <>'DISABLED'; will give me a list of all jobs that I have to monitor and that are not in the disabled state. But how can I verify that the jobs are running at their scheduled date time?
    Any help please? I need to create a view of all such jobs and then plan to send an alert so that appropriate action can be taken and it is assured that all important jobs run as per schedule.
    Thanks.

    Hi,
    I can see 2 approaches.
    - for jobs that have run but ran very late you should query dba_scheduler_job_run_details and filter by the difference between req_start_date and actual_start_date
    - for jobs that should have run but shouldn't, query for DBA_SCHEDULER_JOBS jobs that are SCHEDULED where next_run_date is in the past
    Hope this helps,
    Ravi.

  • Running job in specific set of App servers

    Hi,
      Is there a way to run jobs based on one of the servers in the group similar to Logon Load balancing.  Otherwise is there a way to avoid running jobs on specific application servers.  We don't want to limit the Job onto one Target server.
    Kindly advise if you have any suggestions/solutions..
    Regards,
    Giridhara

    I have asked this question keeping in mind of running critical jobs to run in specific set of application servers.  Currently I can't run class B type of jobs in specific group.  I would like to schedule jobs with certain class, say classB, to be run in specific app servers.  Is it possible?

  • While running F110 mail trigger should happen at the time of payment Run

    Hi Experts,
    I have configured FBZP and automatic mail trigger for Payment Advice also.  Now while running F110 then at the time of Proposal Run the mail is getting triggered. But since its proposal it can be edited also. So I need the mail should trigger at the time of Payment Run. Plz suggest how to achieve this.
    Thanks in Advance,
    Arabinda

    Check this note: 836169
    may be helpful with the config and setup, its a consulting note....

  • Create a listing of reports with last run date and # of times run

    Hi All,
    I want to create a listing of reports with last run date and number of times report is run in the past 18 months.
    If anybody can please help me with the query for the same.
    Regards,
    Sk
    Edited by: user10989244 on Aug 18, 2009 7:12 AM

    Hi Sk
    Assuming you have the collection of statistics enabled, which it is out of the box, you can get the information you need from the EUL5_QPP_STATS table. This script will help:
    SELECT
    QPP.QS_DOC_OWNER WORKBOOK_OWNER,
    QPP.QS_DOC_NAME WORKBOOK_NAME,
    QPP.QS_DOC_DETAILS WORKSHEET_NAME,
    QPP.QS_CREATED_BY RUN_BY,
    TRUNC(MAX(QPP.QS_CREATED_DATE)) LAST_USED_DATE,
    COUNT(QPP.QS_ID) TIMES_USED
    FROM
    EUL5_QPP_STATS QPP
    WHERE
    QPP.QS_CREATED_DATE >= ADD_MONTHS(SYSDATE, -18)
    GROUP BY
    QPP.QS_DOC_OWNER,
    QPP.QS_DOC_NAME,
    QPP.QS_CREATED_BY,
    QPP.QS_DOC_DETAILS
    ORDER BY 1,2,3;
    Best wishes
    Michael

  • DS 4.2 get ECC CDHDR deltas in ABAP data flow using last run log table

    I have a DS 4.2 batch job where I'm trying to get ECC CDHDR deltas inside an ABAP data flow.  My SQL Server log table has an ECC CDHDR last_run_date_time (e.g. '6/6/2014 10:10:00') where I select it at the start of the DS 4.2 batch job run and then update it to the last run date/time at the end of the DS 4.2 batch job run.
    The problem is that CDHDR has the date (UDATE) and time (UTIME) in separate fields and inside an ABAP data flow there are limited DS functions.  For example, outside of the ABAP data flow I could use the DS function concat_date_time for UDATE and UTIME so that I could have a where clause of 'concat
    _date_time(UDATE, UTIME) > last_run_date_time and concat_date_time(UDATE, UTIME) <= current_run_date_time'.  However, inside the ABAP data flow the DS function concat_date_time is not available.  Is there some way to concatenate UDATE + UTIME inside an ABAP data flow?
    Any help is appreciated.
    Thanks,
    Brad

    Michael,
    I'm trying to concatenate date and time and here's my ABAP data flow where clause:
    CDHDR.OBJECTCLAS in ('DEBI', 'KRED', 'MATERIAL')
    and ((CDHDR.UDATE || ' ' || CDHDR.UTIME) > $CDHDR_Last_Run_Date_Time)
    and ((CDHDR.UDATE || ' ' || CDHDR.UTIME) <= $Run_Date_Time)
    Here are DS print statements showing my global variable values:
    $Run_Date_Time is 2014.06.09 14:14:35
    $CDHDR_Last_Run_Date_Time is 1900.01.01 00:00:01
    The issue is I just created a CDHDR record with a UDATE of '06/09/2014' and UTIME of '10:48:27' and it's not being pulled in the ABAP data flow.  Here's selected contents of the generated ABAP file (*.aba):
    PARAMETER $PARAM1 TYPE D.
    PARAMETER $PARAM2 TYPE D.
    concatenate CDHDR-UDATE ' ' into ALTMP1.
    concatenate ALTMP1 CDHDR-UTIME into ALTMP2.
    concatenate CDHDR-UDATE ' ' into ALTMP3.
    concatenate ALTMP3 CDHDR-UTIME into ALTMP4.
    IF ( ( ALTMP4 <= $PARAM2 )
    AND ( ALTMP2 > $PARAM1 ) ).
    So $PARAM1 corresponds to $CDHDR_Last_Run_Date_Time ('1900.01.01 00:00:01') and $PARAM2 corresponds to $Run_Date_Time ('2014.06.09 14:14:35').  But from my understanding ABAP data type D is for date only (YYYYMMDD) and doesn't include time, so is my time somehow being defaulted to '00:00:00' when it gets to DS?  I ask this as a CDHDR record I created on 6/6 wasn't pulled during my 6/6 testing but this 6/6 CDHDR record was pulled today.
    I can get  last_run_date_time and current_run_date_time into separate date and time fields but I'm not sure how to build the where clause using separate date and time fields.  Do you have any recommendations or is there a better way for me to pull CDHDR deltas in an ABAP data flow using something different than a last run log table?
    Thanks,
    Brad

  • What dictionary to see how long a job has run??

    Hi, all.
    I would like to check how long a job has run.
    dba_scheduler_job_run_details.LOG_DATE - dba_scheduler_job_run_details.ACTUAL_DATE
    = the time a job has run.
    Is this right?
    Thanks and Regards.

    Dear Chandra.
    Thanks for your reply.
    Have a good night.
    Best Regards.

  • Long running job in BW

    Hello Gurus,
           which transaction code can be used to show up all long-time running jobs in bw?  how can we identify if a job is running too long?
    Many thanks,
    frank

    Hi,
    Please check the below
    SM66 - Global Work Process Overview
    SM37 - Simple Job Selection ( Only active jobs)
    SM50 - Process Overview
    Sort them by Time
    -Vikram

  • Prgess indicator on long running jobs

    I have an FX application that is directly linked to my database. The program allows all DML operations as well as user defined actions (action commands and various other methods). I have the same application running in Swing, SWT, Canoo ULC and al works just fine. In each of the other front end types, the application automatically displays a busy indicator when a long running job is executed. Now I need this in FX.
    My application is basically a Rich Client framework which allows the same business logic and forms to have different front ends depending on customer requirements. The application is built by customers in a 4GL style development tool. The application is actually built at run time and the data is provided by the user through various services. Because I am building an FX program for a framework, I don't know when the user may execute a long running job when, for example, a button is pressed. I have full control over the retrieval and modification of data but not user interaction. I am therefore looking for a busy indicator that comes automatically when the main thread is waiting.
    Any help would be great!

    Hi guys and thanks for your answers
    I may have stretched the mark with "long running jobs" by these I mean a database query, a price calculation, order process etc. These are standard jobs that are issued on a Rich Client application. Basically I have a screen which will execute a query, and I want to give the user feedback when the query is executing so that he doesn't think that the application has hung. In Swing I have done this by creating my own event queue with a delay timer:
    public class WaitCursorEventQueue extends EventQueue implements DelayTimerCallback
        private final CursorManager cursorManager;
        private final DelayTimer    waitTimer;
        public WaitCursorEventQueue(int delay)
            this.waitTimer = new DelayTimer(this, delay);
            this.cursorManager = new CursorManager(waitTimer);
        public void close()
            waitTimer.quit();
            pop();
        protected void dispatchEvent(AWTEvent event)
            cursorManager.push(event.getSource());
            waitTimer.startTimer();
            try
                super.dispatchEvent(event);
            finally
                waitTimer.stopTimer();
                cursorManager.pop();
        public AWTEvent getNextEvent() throws InterruptedException
            waitTimer.stopTimer(); // started by pop(), this catches modal dialogs
            // closing that do work afterwards
            return super.getNextEvent();
        public void trigger()
            cursorManager.setCursor();
    }I then implemented this into my application like this:
    _eventQueue = new WaitCursorEventQueue(TIMEOUT);
    Toolkit.getDefaultToolkit().getSystemEventQueue().push(_eventQueue);Now each time the application waits for a specific time, the cursor will become a wait timer. This give s the user a visual feedback so that he knows that the application is working and not just hung. By doing this, I do not need to wrap each user callout in a timer. Much easier like this!
    I would like to implement the same in FX.
    Edited by: EntireJ on Dec 15, 2011 12:34 AM

  • Trigger Alert for Long Running Jobs in CPS

    Hello,
    I am currently trying to make a trigger so that I can monitor the long running jobs in the underlying ERP. Can you help me on the APIs to use?
    Im trying to modify my previous alert - Chekcing of failed jobs
      // only check error jobs
      if (jcsPostRunningContext.getNewStatus().equals(JobStatus.Error)) {
        String alertList = "email address ";
        String [] group = alertList.split(",");
        for (int i = 0; i < group.length; i++) {
          JobDefinition jobDefinition = jcsSession.getJobDefinitionByName("System_Mail_Send");
          Job aJob = jobDefinition.prepare();
          aJob.getJobParameterByName("To").setInValueString(group<i>);
          aJob.getJobParameterByName("Subject").setInValueString("Job " + jcsJob.getJobId() + " failed");
          aJob.getJobParameterByName("Text").setInValueString(jcsJob.getDescription());
    Im trying to look for the API so I can subtract the system time and the start time of the job and compare it to 8 hours?
    if (jcsPostRunningContext.getNewStatus().equals(JobStatus.Error)) {    <--  Can I have it as ( ( Start Run Time - System Time ) > 8 Hours )
    Or is there an easier way? Can somebody advise me on how to go about this one?

    Hi,
    You can do it using the api:
    if ((jcsJob,getRunEnd().getUTCMilliSecs() - jcsJob.getRunStart().getUTCMilliSecs()) > (8*24*60*1000))
    This has the drawback that you will only be notified when the job finally ends (maybe more then 8 hours!).
    The more easier and integrated method is using the Runtime Limits tab on your Job Definition or Job Chain. This method can raise an event when the Runtime Limit is reached. The event can trigger your notification method.
    Regards Gerben

  • How to research a long running job from 3 days ago

    Re: How to research a long running job from 3 days ago
    Client called to say that a job that normally runs for 6 hours ran for 18 hours on 11/01. 11/01 was a Saturday, and end of month. The long running job writes to a log and I can from the log that that the problem started right around 10:43am. Every step
    before 10:43 was taking the normal amount of time. Then at 10:43 a step that takes seconds hung for 12 hours. After 12 hours the step finished and the job completed successfully.
    I looked at the SQL Log, Event Log, Job History (for all jobs). What else can I look at to try and resolve an issue that happened on 11/01/2014?

    It does execute an SSIS package.
    Personally I feel this as kind of bug in SSIS package but I am not expert in SSIS so I would move it to SSIS forum. Please update your question giving complete information what SSIS package does.
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it
    My Technet Wiki Article
    MVP

  • Sometimes my computer takes too long to connect to new website. I am running a pretty powerful work program at same time, what is the best solution? Upgrading speed from cable network, is it a hard drive issue? do I need to "clean out" the computer?

    Many times my computer takes too long to connect to new website. I have wireless internet (time capsule) and I am running a pretty powerful real time financial work program at same time, what is the best solution? Upgrading speed from cable network? is it a hard drive issue? do I only need to "clean out" the computer? Or all of the above...not to computer saavy.  It is a Macbook Pro  osx 10.6.8 (late 2010).

    Almost certainly none of the above!  Try each of the following in this order:
    Select 'Reset Safari' from the Safari menu.
    Close down Safari;  move <home>/Library/Caches/com.apple.Safari/Cache.db to the trash; restart Safari.
    Change the DNS servers in your network settings to use the OpenDNS servers: 208.67.222.222 and 208.67.220.220
    Turn off DNS pre-fetching by entering the following command in Terminal and restarting Safari:
              defaults write com.apple.safari WebKitDNSPrefetchingEnabled -boolean false

  • Re:How to determine the long running jobs in a patch

    Hi ,
    How to determine the long running jobs in a patch .
    Regards

    Hi,
    Check the below MY ORACLE SUPPORT note:
    Note.252422.1 .... Check Completed Long Running Jobs In Oracle Apps.
    Best regards,
    Rafi

  • Time checking, running events based on time

    Hi,
    I was hoping someone could suggest a better, or more accepted method that will activate a daily maintenance program based on the time of the day...
    I was thinking along the lines of making a thread that will check the time, sleep for a second, check the time, and so on, and when the time is 12:00 or whatever, it will create and run a maintenance object or thread.
    It seems rather primitive, or crude, so I'm hoping someonne can post a more elegant solution?
    Thanks!

    TimerTask
    http://java.sun.com/j2se/1.3/docs/api/java/util/class-use/TimerTask.html

Maybe you are looking for

  • The volume control on my ipod touch 4th Gen is gone,what should I do?

    It just happen to me lately, so as I open the music while my earhones are plugged,I saw that there is no volume control on my screen but the song is still playing but I can't hear anything so I remove my earphones then I plugged it again then the vol

  • Where is the Command-1 in Messages Beta?

    I have been using Messages Beta for Mac OSX and could chat with friends using their (and my) Yahoo account. Until recently, there were two windows that I could choose from, Command-0 (Messages) and Command-1 (chat window). But the last option has mys

  • Question about sql batch process in java app

    hi all i have few questions about using batch process in the java.sql package. the addBatch method can take sql statements like inserts or updates. can we use a mixture of insert and update then? can we use prepared statement for this? it's just for

  • Problem with Field image recovery software

    Dears, I updated cisco wlc 5508 FUS image, but field recovery image stayed the same, does this mean that fus is not upgraded, what can i do? Manufacturer's Name.............................. Cisco Systems Inc. Product Name............................

  • RMAN on Oracle 8i and 10g Retention Policy

    I have several Oracle 8i and Oracle 10g database instances on a Windows 2003 server. We use RMAN backups on these servers. We run a batch job daily to database backups. We create RMAN level 0 on Sunday, Thursday level 1, Tuesday, Thursday, Friday, an