How long has the current SPID/Agent Job been running

I have a SQL Agent Job that has 15 steps. Each step executes the same CLEANUP sproc against a database. STEP1 executes CLEANUP against DB1, STEP2 executes CLEANUP against DB2, etc. These 15 databases all have the exact same schema (that was the design
decision - not going to change).  The job can run for days. I want to have a MAXMINUTESTORUN configuration (probably set to 4 hours) that the sprocs will check and when that is exceeded the sprocs will nicely terminate and then pick up  again
the next time. I want to be able to ask in the sproc, how long has the spid/agent job been running. How is the best way to do this?

Well, the idea for that, 
the clean up always runs first on the database it never before and then it will run against the database that has oldest 'Lastrun". you can change this logic if you need.
Using the demo scripts above, try this ...after the scheduling the job.
1. run the job once..it will run the procedure for testA
2.check the output of select * from msdb.dbo.cleanupjob
3. run the job again..it will run the procedure for testB(the reason it picks this is because the cleanup procedure never ran for database testb)
4.check the output of select * from msdb.dbo.cleanupjob
5. run the job again..it will run the procedure for testA(the reason it picks this is because the cleanup procedure ran for database testb atleast once and 
will the pick the  oldest "last run " database)
6.check the output of select * from msdb.dbo.cleanupjob
you can also ,,replace this block
select top 1 @a= databasename from
(select top 1 1 source,databasename from cleanupjob
where (lastrun is null)
union
select top 1 2 source,databasename from cleanupjob
where (lastrun in (select min(lastrun) from cleanupjob where lastrun is not null))
order by source) A
with 
select top 1 @a=databasename from msdb.dbo.cleanupjob where isnull(lastrun,'19000101') in (select min(isnull(lastrun,'19000101')) from msdb.dbo.cleanupjob)
order by id
Hope it Helps!!

Similar Messages

  • HT1600 How long does the current Apple,TV software download take

    How long does the current Apple TV software up date take , or should it take ..?

    Depends on your internet connection.  Mine is usally done in a few menutes, but I have seen the install part take up to 45 min.

  • How to get the current request id in a running request?

    How to get the current request id in a running request?
    Thanks.

    Did you notice that there's a whole section on this forum dedicated to this topic, called E-Business Suite?
    C.

  • How long has the lines issue been around?

    Just curious. I just got my new powerbook and I am fairly upset at the presence of these lines. Is this something that apple has known about for months or is this a new issue all together? Basically, i just want to know how long everyone has been waiting for an announcment on this issue.

    Well, a more precise answer is :
    PB15"HiRes release : Oct. 19th
    First post on horizontal lines : Oct 25th.
    L.

  • How long has the 'hey siri' function worked unplugged?

    I use my idevices and siri everyday for hours, I'm familiar with all of ios' functions. But I just discovered while using my iPhone 6 with ios 8.3 that after you hold the home button down activating siri, then ask a question, as long as you keep the siri screen open the 'hey siri' function works unplugged. Has this been the case since ios 8.0?

    simonp_au wrote:
    Ok, well after I press the home button as usual (unplugged), then ask siri a question, siri then answers. That's the way it has always worked, yes. But, if you leave the siri screen open, while unplugged, then say 'hey siri' siri activates again. Try it. And that has not always been an available function.
    I can confirm that it works. My recollection is that Siri always remained open for a minute or so after a query, but you would have to push HOME again for another question. Nice feature!

  • How Long Has The iCloud Website Been Crashing?

    I recently had to get a new iPhone, well iCloud doubled my contacts so I went into the iCloud website to delete my extra contacts and everytime I go to delete the selected contacts iCloud crashes and closes my safari window. Anyone else having this problem?

    Well, a more precise answer is :
    PB15"HiRes release : Oct. 19th
    First post on horizontal lines : Oct 25th.
    L.

  • I had completed my iDVD project and burned a disc. It worked great! Then someone messed with the project and put a red frame around the opening screen. Now when I burn the project, it no longer has the opening frame. How can I fix?

    I had completed my iDVD project, a Wedding Slideshow with pictures and music, and burned it on a disc. It worked great! Then someone messed with the original project on my computer and clicked around and put a red frame around the opening screen that has the Wedding theme with music. Now when I burn the project to make more DVDs, it burns but no longer has the opening frame. It immediately opens to the iMovie slideshow. How can I fix so I can burn the entire project with opening frames?

    As Bengt suggested make a disk image of the successfully burned DVD using Disk Utility. Then you can burn copies any time you need one.
    In the future once you have the project as you want it save it as a disk image via the File ➙ Save as Disk Image menu option.  This will separate the encoding process from the burn process. 
    To check the encoding mount the disk image and launch DVD Player and play it.  If it plays OK with DVD Player the encoding was good.
    You can then burn it to disk with Disk Utility at the slowest speed available to assure the best burn quality.  Always use top quality media:  Verbatium, Maxell or Taiyo Yuden DVD-R are the most recommended in these forums.
    OT

  • HT4623 Hi!My iPAD lost its charge fast !!I've got an iPAD capacity 57,1GB and it has available 55,1GB ,version 7.0.4 .I'd like to know how long does the battery last when it is 100 % charged.

    Hi!I've just installed the iOS 7.0.4 operating system and the battery lost its charge at an incredibly speed.I'd like to know how long does the battery last if everything is right when it has 100% charge.Thanks!

    I`m `propping` up this thread to to the top of the forums again as it`s been three months and not a single community member or Apple support personnel have replied, which I find discouraging.
    I`ve tried everything - both the iOS device(s) and Apple TV have been upgraded (albeit reluctantly) to the latest versions, since iOS 7 looks like crap compared to iOS 6. Both use the same WiFi network. Bluetooth is set to `off`, as per the online tutorials on the Apple Support page.
    I also tried shutting all of them down, including the router, waiting 30 seconds and turning the router, then the Apple TV then the iOS device on sequentially with 30 seconds in between each, again as per this discussion forum, and still nothing.
    Why can Apple not make a technology, such as AirPlay, work with greater than 10%?
    Any other ideas?
    Come on, people.
    Thanks,
    Doug

  • How to get the current path of my application in java ?

    how to get the current path of my application in java ?
    thanks

    To get the path where your application has been installed you have to do the following:
    have a class called "what_ever" in the folder.
    then you do a litte:
    String path=
    what_ever.class.getRessource("what_ever.class").toString()
    That get you a string like:
    file:/C:/Program Files/Cool_program/what_ever.class
    Then you process the result a little to remove anything you don't want:
    path=path.substring(path.indexOf('/')+1),path.lastIndexOf('/'))
    //Might be a little error here but you should find out //quickly if it's the case
    And here you go, you have a nice
    C:/Program Files/Cool_program
    which is the path to your application.
    Hooray

  • How to check the current EHP stack level? in SAP

    Dear All,
    How to check the current EHP stack level? in SAP  . i have checked forum before i am posting but still comfused .
    same one said SAP_APPL , EA_Appl  and SAP _HR is 60n if n=1.2.3.4. if n =1 is enhanced package 1 similarly 2,3,4 .
    some one said SAP_BASIS 701,702,703,704 . according ehp1,2,3,4.
    Pls check the details and confirm either is ehp1 or ehp4 .
    Component version is simply shows SAP ECC 6.0 in system -> status.
    Software Component  - Release  - SP level
    SAP_ABA     701     0007
    SAP_BASIS     701     0007
    PI_BASIS     701     0007
    ST-PI     2008_1_700     0003
    SAP_BS_FND     701     0008
    SAP_BW     701     0007
    SAP_AP     700     0021
    WEBCUIF     700     0008
    SAP_APPL     604     0008
    SAP_HR     604     0029
    SAP_HRCAR     604     0029
    SAP_HRCAT     604     0029
    SAP_HRCAU     604     0029
    SAP_HRCBE     604     0029
    SAP_HRCBR     604     0029
    SAP_HRCCA     604     0029
    SAP_HRCCH     604     0029
    SAP_HRCCL     604     0029
    SAP_HRCCN     604     0029
    SAP_HRCDE     604     0029
    SAP_HRCDK     604     0029
    SAP_HRCES     604     0029
    SAP_HRCFI     604     0029
    SAP_HRCFR     604     0029
    SAP_HRCGB     604     0031
    SAP_HRCHK     604     0029
    SAP_HRCID     604     0029
    SAP_HRCIE     604     0029
    SAP_HRCIN     604     0029
    SAP_HRCIT     604     0029
    SAP_HRCJP     604     0029
    SAP_HRCKR     604     0029
    SAP_HRCMX     604     0029
    SAP_HRCMY     604     0029
    SAP_HRCNL     604     0029
    SAP_HRCNO     604     0029
    SAP_HRCNZ     604     0029
    SAP_HRCPH     604     0029
    SAP_HRCPT     604     0029
    SAP_HRCRU     604     0029
    SAP_HRCSE     604     0029
    SAP_HRCSG     604     0029
    SAP_HRCTH     604     0029
    SAP_HRCTW     604     0029
    SAP_HRCUN     604     0029
    SAP_HRCUS     604     0029
    SAP_HRCVE     604     0029
    SAP_HRCZA     604     0029
    SAP_HRGXX     604     0029
    SAP_HRRXX     604     0029
    EA-IPPE     400     0018
    EA-APPL     604     0008
    EA-DFPS     600     0018
    EA-FINSERV     604     0007
    EA-GLTRADE     604     0008
    EA-HR     604     0029
    EA-HRCAR     604     0029
    EA-HRCAT     604     0029
    EA-HRCAU     604     0029
    EA-HRCBE     604     0029
    EA-HRCBR     604     0029
    EA-HRCCA     604     0029
    EA-HRCCH     604     0029
    EA-HRCCN     604     0029
    EA-HRCDE     604     0029
    EA-HRCDK     604     0029
    EA-HRCES     604     0029
    EA-HRCFI     604     0029
    EA-HRCFR     604     0029
    EA-HRCGB     604     0029
    EA-HRCHK     604     0029
    EA-HRCID     604     0029
    EA-HRCIE     604     0029
    EA-HRCIN     604     0029
    EA-HRCIT     604     0029
    EA-HRCJP     604     0029
    EA-HRCKR     604     0029
    EA-HRCMX     604     0029
    EA-HRCMY     604     0029
    EA-HRCNL     604     0029
    EA-HRCNO     604     0029
    EA-HRCNZ     604     0029
    EA-HRCPH     604     0029
    EA-HRCPT     604     0029
    EA-HRCRU     604     0029
    EA-HRCSE     604     0029
    EA-HRCSG     604     0029
    EA-HRCTH     604     0029
    EA-HRCTW     604     0029
    EA-HRCUN     604     0029
    EA-HRCUS     604     0029
    EA-HRCVE     604     0029
    EA-HRCZA     604     0029
    EA-HRGXX     604     0029
    EA-HRRXX     604     0029
    EA-PS     604     0007
    EA-RETAIL     604     0007
    FINBASIS     604     0008
    ECC-DIMP     600     0018
    ERECRUIT     604     0008
    FI-CA     604     0008
    FI-CAX     604     0007
    INSURANCE     600     0018
    IS-CWM     600     0018
    IS-H     600     0024
    IS-M     600     0018
    IS-OIL     600     0018
    IS-PS-CA     604     0007
    IS-UT     600     0018
    LSOFE     600     0018
    SEM-BW     604     0008
    ST-A/PI     01M_ECC600     0001
    Regards
    Edited by: satheesh0812 on Nov 17, 2011 7:57 AM

    Hi Sateesh,
    SAP_ABA 701 0007
    SAP_BASIS 701 0007
    PI_BASIS 701 0007
    ST-PI 2008_1_700 0003
    SAP_BS_FND 701 0008
    SAP_BW 701 0007
    SAP_AP 700 0021
    WEBCUIF 700 0008
    SAP_APPL 604 0008
    Based on the component information provided by you, I can conclude that your system is ECC 6.0 EHP4.
    EHP4 is derived from your component SAP_APPL 604.
    In addition to this your EHP4 system has NW stack on NW 7.0 EHP1.
    Hence your system is ECC 6.0 EHP4 with NW 7.0 EHP1.
    Hope this answers your query.
    Regards,
    Deepak Kori

  • HT5262 How long should the icloud back up take?

    How long should the iCloud back up take? I only have 4gb of storage but it has taken almost an hour already with approximately 2 hours remaining. 

    Hi RMaskery14,
    If you are concerned about the time your iCloud backup is taking, you may find the following article helpful:
    My backup is taking a long time to finish.
    Backing up and restoring takes time, especially if you have a lot of data or a slow connection. Depending on the size of your backup and the speed of your network, you may need more time than expected to complete the process. Using a reliable connection when backing up your device is highly recommended.
    iCloud: Troubleshooting creating an iCloud backup
    http://support.apple.com/kb/ts3992
    Regards,
    - Brenden

  • How to get the current page URL

    HI All
    I am working in oracle apps 4.0
    I have one page called history in that i have one page item called Application url. My application id is 122 but its a copy of application 106
    How to get the current page url for the page item.
    Any steps should be help ful
    Thanks & Regards
    Srikkanth.M

    I'm not 100% clear on what the requirement is from the description, however it does sound like you are making things unnecessarily complicated.
    If you want permanent/ID-independent links then use application and page aliases.
    so here we used to display the url like this: <tt>{noformat}http://81.131.254.171:8080/apex/f?p=122{noformat}</tt>
    Do you mean that the URL is displayed like that? If so that doesn't seem particularly helpful. How is anyone supposed to know what it is?
    There are many ways to provide links in APEX&mdash;including lists and nav bars.
    Where the link is to another resource located on the same server (such as another page in the same app, or a different app in the workspace), relative addressing can be used, making it unecessary to include scheme, domain and port information in the URL. For example, if the page to be linked to has a page alias <tt>ABOUT</tt> in an application with alias <tt>UNITY</tt>, and the apps share an authentication scheme/cookie to permit shared sessions, then the link URL is simply
    f?p=UNITY:ABOUT:&APP_SESSION.

  • How to get the Current User on the UI page?

    All,
    Could you please let me know how to get the Current user on the UI input page , i need to display the current user ID when some one clicks the submit button, i want o get the current user to display in the javascript alert box.
    Edited by: 951930 on Oct 24, 2012 12:21 PM

    lucky,
    my schema has already defined for
    <user mapField="USER_ID" default="%CurrentUser"/>
    and in my UI page
    <td oraLabel="user"></td><td oraField="user" id="userId" ></td>
    and my javascript
    function showUserId () {                        
    var curUser = document.getElementById('userId').value;
    alert(curUser);
    and i have called this function on my submit button, but i am not able to get Current Logged User ID value to show in the alert nor able to show the current logged user on the UI page.
    my requirement is on custom UI page i need to show Current Logged User in one corner of the page and also need to show the same user in alert when he submits the button.
    Appreciate for the help.
    Edited by: 951930 on Oct 25, 2012 8:42 AM
    Edited by: 951930 on Oct 25, 2012 9:06 AM

  • How to get the current week from sysdate?

    Hi sir,
    i want to know how to get the current week from sysdate?
    thanks

    Hi Nicolas
    It seems you like to check my post and also make commend ;) thanks for your attention
    Have you ever read the posts above and given solutions ?Yes, I did
    Have you read the docs ? Yes, I checked
    What's the added value here ?Did youYou shared doc with solution(long one), I shared short one which point same solution(Check what Joel posted)..So what is benefit, As you can guess oracle docs are sometimes become so complicated as specialy for beginner...(At least it was like that for me and Belive me somedocs are still sooo complicated even for oracle coworkers ) But for you I dont know ;)
    => Why writting the PS in bold ?Why.. Let me think... Ohh Maybe I am looking some questions(many) and even user get answer they should not changed status so I am reading some posts and try to get problem and loosing time..
    So I am putting that PS wiht BOLD because I dont wanna lose time my friend ;) Because While I am trying to help ppl here In same time I am trying to giving support to my customer prod systems. Which mean time is very important for me...
    Hope my answer could satisfy you..
    One important PS for you.. You may not like my posts (or someone) but my friend I become tired to read&answer and make commend to on your comment which is about my posts.
    I am not newbie in forum(At least I fell like that) and I belive I know how I should make post..
    Thank you
    Regards
    Helios

  • How to Get the Current Workitem id at runtime

    Hi All,
    I have a scenario, where request pending with a user who has already resigned the organization. The requirement is that we need to provide a report
    of the request and with whom it is pending with along with the workitem id with a forward push button.
    So that if the user identifies that a request is pending with someone he can click the record and press for the forward button and a pop-up to be showed where he can enter the userid to whom he needs to forward it.
    In this scenario can anyone tell me how to get the current workitem id at run time and to save it to a custom table.
    I tried with method before workitem execution, but here i am not getting the current workitem id.
    Can you please suggest a good solution for this.
    Thanks and Regards,
    Balaji

    Karri,
    I think i can explain you with an example.
    Here is my Scenario.
    A user has raised a Gate pass and it went to all approval's and got approved and the material is also sent out from the plant. Lets take the date as 1.1.2013 (A Warehouse person have done the checking and sent out of the plant).
    On 1.3.2013 some of the material has been returned and a material inward request has been raised and now the warehouse person has to do a inward checking and to sent it back for the initiator for the approval, but the warehouse person has resigned the organization on 1.2.2013, now the workitem is pending with the warehouse person who has already resigned.
    My scenario is once the material inward request is created and before the workitem is delivered to the warehouse person i need to get the workitem id and to store the workitem some where.
    So that in future if any warehouse dept head wants to forward the workitem which are lying in the person inbox who has already resigned he can do it via a report using this workitem id.
    So, can anyone help how to get the dialog workitem id before the workitem creation or execution. I tried with "method before workitem execution" but my break point is not triggering at this point.
    Thanks and Regards,
    Balaji

Maybe you are looking for

  • What's the process of uploading videos to youtube?

    This might sound like a silly question... but what is the process of uploading videos to youtube? Does the video get processed into youtube friendly format and then get uploaded to youtube? So therefore, no re-processing is required on youtube? And t

  • Catalyst 3750 Software Upgrade in a Stack Configuration

    I tryed to upgrade IOS using only copy command into flash: and after my 2nd member of stack didn't up - i got next message= Mar 1 00:03:31.846: %IMAGEMGR-6-AUTO_COPY_SW_INITIATED: Auto-copy-software process initiated for systems[bits: 0x0001] *Mar 1

  • Mavericks and iPhoto, help!

    I updated to Mavericks and no my old iPhoto will not open.  Any idea how I can get my old photos back?  I know that I should but I do not have a backup.  Please help me, I desperately want my old photos back!

  • How to intercept RMI calls over JRMP?

    Hi, I would like intercept calls over RMI/JRMP to pass contextual data between client and server. I was able to do it for IIOP using Portable Interceptor but could not find any solution for JRMP. Is there any other way to implicitly pass data between

  • Programs that would work with Lumia 900 and an older Mac model (Mac HD)

    Hi so like the title im trying to sync my lumia 900 with my very old Mac (Mac HD not lion etc..). Any ideas where I could buy/get the software?