Capture duration time and use it in customized the SQL Server Job System Message

Hi there
I am trying to capture the job duration time and put it on the customized Job email subject.
This is the original message from SQL server, the Bold one is what I am trying to capture.
JOB RUN:            
'Hello' was run on 7/30/2014 at 8:05:00 AM
DURATION:       
0 hours, 0 minutes, 2 seconds
STATUS:              
Succeeded
MESSAGES:        The job succeeded. 
The Job was invoked by Schedule 27 (Job 2).  The last step to run was step 1 (Test).
Is there anyway to do that? I have tried to pull it from jobhistory and I did't have any luck.
Cheers,
Matt

You can take this code and send it to a table, then create your reports
; WITH CTE as -- Use a Simple Common Table Expression
SELECT ROW_NUMBER() OVER (PARTITION BY job_name -- Add the comma separate columns that need to be unique in the table
ORDER BY ( SELECT 0 ) ) RN ,* -- If the order does not matter on the one you want to keep - the select 0 work well; otherwise add the appropriate order by to make the row you want to keep appear at the top
FROM (
select TOP 100000 job_name, run_datetime, run_duration,run_status
from
select job_name, run_datetime,run_status,
SUBSTRING(run_duration, 1, 2) + ':' + SUBSTRING(run_duration, 3, 2) + ':' +
SUBSTRING(run_duration, 5, 2) AS run_duration
from
select DISTINCT
j.name as job_name,
run_datetime = CONVERT(DATETIME, RTRIM(run_date)) +
(run_time * 9 + run_time % 10000 * 6 + run_time % 100 * 10) / 216e4,
run_duration = RIGHT('000000' + CONVERT(varchar(6), run_duration), 6)
,h.run_status
from msdb..sysjobhistory (NOLOCK)h
inner join msdb..sysjobs (NOLOCK)j
on h.job_id = j.job_id
where h.step_id = 0
) t
) t
order by job_name, run_datetime desc
)X
SELECT @@servername as [ServerName],RN,job_name,run_datetime,run_duration,run_status
FROM CTE
ORDER BY run_duration desc
Javier Villegas |
@javier_vill | http://sql-javier-villegas.blogspot.com/
Please click "Propose As Answer" if a post solves your problem or "Vote As Helpful" if a post has been useful to you

Similar Messages

  • Please ... tell me how to download and instale the setup for the SQL Server Express 2012

    My OS is 32-bit and i have already downloaded the SQL Server 2012 Express but i cant find the SQL Server Management studio  so please tell me how can i get it?

    Hello Muhammad,
    if you already install SQL server, to run the Managment Studio you can click Start and Run, and type "SSMS".
    Of course you can create a shortcut and look for the file (this is the installation location you selected during the installation process) using the Windows search (pressing F3 activates the search).
    Tzuri Ben Ezra | My Certifications:
    CompTIA A+ ,Microsoft MCP, MCTS, MCSA, MCITP |
    FaceBook: Tzuri FaceBook | vCard:
    Tzuri vCard | 
    Microsoft ID:
    Microsoft Transcript 
     |

  • Using integrated security to access SQL Server database

    Hi,
    Currently we are using username/password combination to log in to a SQL Server database. These varaiables are defined as environment variables.
    For security reasons we now want to use integrated security of the SQL Server database. This way the connection will be with the NTUser the Nodemanager has been started with.
    Can this be done in Fort�?

    I do not think there is a way to pass the NT user's security authentication over to the DB in UDS.
    ka

  • I use aperture 3 since a long time. Using slit viewer, now the bigger image become bigger then the given space and shifted to the right, so that I can't see the complete picture anymore. And I also don't see the last few picture in the strip below. How ca

    I use aperture 3 since a long time. Using slit viewer, noe the bigger image become bigger then the given space and shifted to the right, so that I can't see the complete picture anymore. And I also don't see the last few picture in the strip below. How can I splve this problem?

    This lloks like your preferences file might have become corrupted.
    you probably have a problem with corrupted user preferences.
    Remove the Preferences: Remove the Aperture's user preferences from the User Library as described here:
    Aperture 3: Troubleshooting Basics   http://support.apple.com/kb/HT3805
    Note:Your User Library is hidden by default in 10.7.x or later - to open it in a Finder window use the "Go" menu from the Finder's main menu bar.
    Quit Aperture, if it is running. Log off and on again.
    Open the user library by using the Finder's "Go > Go to Folder" menu and hold down the options-key, until "Library" appears in the drop down menu. Select it.
    In the widow that will open, scroll down to "Preferences"
    From the "Preferences" folder  remove "com.apple.Aperture.plist".
    Then try to launch Aperture again.
    But deleting the "Preferences" file will cause Aperture to forget the preferences settings. Be prepared to have to reset all options you set using the Aperture Preferences panel.
    Regards
    Léonie

  • If i buy an iphone 5s sprint can i use it for CDMA? I ask that because i went out of the country one time and used it on a CDMA network but that was my iphon 5 not an i phone 5s.

    if i buy an iphone 5s sprint can i use it for CDMA? I ask that because i went out of the country one time and used it on a CDMA network but that was my iphon 5 not an i phone 5s.

    Sprint is a CDMA carrier, same as Verizon so it will work on CDMA.

  • My wifi button is frezon and I tried turning my phone off for a period of time and reset my phone but the button is still frezon it want slide over to turn on my wifi. Is there any other way to fix without going to apple to get it fixed?

    My wifi button is frezon and I tried turning my phone off for a period of time and reset my phone but the button is still frezon it want slide over to turn on my wifi. Is there any other way to fix without going to apple to get it fixed?

    Hey Posada143, You can still try the rice thing, but do not expect much, as roaminggnome has stated. The rice only works if you do it ASAP and leave the iPod off-- do not attempt use, turn on or charge until it is completely dried out. This is probably academic at this point but remember this for the next time: The drying can take 10 days. You put the uncooked rice and iPod in a sealed bag, change the rice every couple of days. This creates a low humidity environment and draws the moisture out of the iPod, but it takes time. Turn your iPod on to earlier, and you run the risk of shorting out, damaging the components inside. Even if done correctly it can spotty. If you do get the iPod to work (and this may require Resetting, Restoring or attempting to place it in DFU recover mode) the first thing you do is make backups, because you never know how long it will continue to work. As for your pictures, if you can't get your iPod to work, you can try data retrieval companies, however; there is no guaranty it will work and it tends to be very expensive. In the future get in the habit of as making backups, because you just don't know. And invest in and use a water tight case. Hope this helps, Good luck. Cheers.

  • Why does the slider disappear every time I use it to move the window (Windows: FF 32.0)?

    Why does the slider disappear every time I use it to move the window (Windows: FF 32.0)? How do I get the slider back?

    Problem solved: I have been using Walnut for Firefox ver. 2.0.28 theme. For some reason this has been causing the problem. Started FF in Safe Mode, and the slider problem disappeared. Then proceeded to re-enable the Walnut theme: the problem reappeared. Disabled Walnut theme and reenabled all my other add-ons (about 6 of them). Still no problem. So, clearly there is a problem with the use of Walnut theme in FF ver. 32, at least on my Windows 7 installation.
    Thanks for all your suggestions and help. Good job, all!

  • TS3681 I have tried restoring my I-phone at least a dozen time and it keeps freezing at the Restoring Iphone Firmware step.. It has now discovers IOS7.1 so I thought it would pregress right through but stuck for 4 hours on restoring Iphone firmware?

    I have tried restoring my I-phone at least a dozen time and it keeps freezing at the Restoring Iphone Firmware step.. I had not been using this phone since October as I updated to the 5c and have had my kids using this for games.. About a month ago I thought it would be useful to update the IOS after I had updates the 5c but this crashed and it has not worked since..
    I have reinstalled Itunes - I have just updated again now that IOS7.1 has come thought and I though I may be there as each step of the restore seemed to be working and the line under the apple logo was progressing. However it has now has now been stuck for 4 hours on restoring Iphone firmware?

    After 4 hours of frozen screen is came up with an error message - Error (3)...Any solutions??

  • It is very difficult to navigate on facebook via safari. The IPAD does not allow other browsers to download and use it almost prevents the facebook app and the lack of scrolling the page.

    It is very difficult to navigate on facebook via safari. The IPAD does not allow other browsers to download and use it almost prevents the facebook app and the lack of scrolling the page.

    I also have problems with Facebook on my iPad 2. I don't do a lot with Facebook and generally only post on my feed page. Sometimes hitting return on the keyboard enters the comment, sometimes not. Sometimes the comment will show on my iPad but if I revisit that page I find that the comment has disappeared. So I'd say that Facebook and my iPad are not totally compatible with each other.
    I looked into Friendly and was about to purchase this free ap. But before I did I went to the Friendly web page for more info. There I found a page with users comments. One after another users complained about bugs with Friendly. The developers claimed a fix was coming but the user comments complained about the lack of response and support. One of the fixes suggested by the developers was to log out of Friendly then log back in. One user complained that doing this three times in ten minutes was not very helpful. Because of this I decided to avoid Friendly.
    I did find a Facebook developed ap but it was for the iPhone. I presume that iPhone aps will work on the iPad but I'll wait until Facebook releases an iPad compatible ap. If there is an ap developed by Facebook for the iPad that I missed please let me know.

  • I bought an Apple TV and used its yesterdary all the day...when I rented a film, its spend about 4 hours to charge... I think it isn't normal... Did Apple had some problem in their network yesterday? Do you have some clue to me? Tks and Rgds

    I bought an Apple TV and used its yesterdary all the day...when I rented a film, its spend about 4 hours to charge... I think it isn't normal... Did Apple had some problem in their network yesterday? Do you have some clue to me? Tks and Rgds

    Download time is mostly related to your internet connection speed.  Beside, there's no need to wait for the entire movie to download before you start watching it; only some buffer needs to be downloaded.  When the buffer is filled, you should get a message that your rented movie can now be watched which usually happen within a minute of the purchase on standard cable connection.

  • Where and how do I get the SQL Query used by the Microsoft Generic Report Library - Alerts?

    Background:
    I'm tasked with the following: I need to create a new Report and the SQL
    The two canned reports that I can pattern after are: Microsoft Generic Report Library
    - Alerts (there is also an alert detail report that can be chosen within the alert report that we may want to use instead)
    - Most Common Alerts
    I'm trying to do this:
    Add another parameter to search on customfield3.
    It should be able to report on all alerts that were assigned to the specific team for the time period along with the top 10 (most common alerts) assigned to the team for the time period.
    Choose as the objects (group) all servers, but Imay need to adjust the report to just look at all alerts without having to provide objects or a group
    The struggle I'm having is: I know SQL. I know how to create an RDL file.
    But Where are the RDL files for the canned reports so I can modify the canned RDL and modify its SQL and forms?
    What is the SQL/ where can I find the SQL used for the Generic Report Library -> Alerts

    Easy but you need to extract it from Microsoft Generic Report Pack. 
    So.. the procedure is as follows:
    1) You export and unseal Management Pack from your SCOM using
    Boris's OpsgMgr tools (MPViewer
    2.3.3)
    2) Ok you've got unsealed xml, now the tricky part, use
    MpElementsExtract tool, example of usage:
    MPElementsExtract.exe <MP.xml> /ex /destination:<destination>
    That you way you get several folders out of mp:
    DWScripts, DWSubScripts, LinkedReports, ReportResources, Reports
    Take a look into content of first 2, there will be pure sql scripts, and rdl's are in Reports folder :)
    Other way is to just use SQL profiler and catch SQL query while generating report. 
    --- Jeff (Netwrix)

  • My Iphone will not let me download apps because it says my apple id is disabled, I have changed my password four times and it still is saying the same thing. What do I do now?

    My Iphone will not let me download apps because it says my apple id is disabled, I have changed my password four times and it still is saying the same thing. What do I do now?

    Contact iTunes to re-enable your account at expresslane.apple.com
    You can reach them by chat or email.

  • Why is "Photos" so awful?  iPhoto was simple, intuitive, easy to organize and use. Photos is the opposite of that.

    Why is "Photos" so awful?  iPhoto was simple, intuitive, easy to organize and use. Photos is the opposite of that.

    pjonesCET1 wrote:
    You can't once installed you can't use iPhoto, anymore in fact I think it is physically removed when you install the 10.10.3 Update.
    Incorrect. iPhotos is not removed at all. It can still be used as long as you have kept your Software up to date. Otherwise
    Is Iphoto gone ? i want it back!
    Pete

  • My mac will not copy more than one file at a time and gets locked up if the file is too large, my mac will not copy more than one file at a time and gets locked up if the file is too large

    my mac will not copy more than one file at a time and gets locked up if the file is too large, my mac will not copy more than one file at a time and gets locked up if the file is too large

    So now that you have repeated the same thing three times that doesn't make things any clearer at all.
    You are copying files from where to where?
    How are you attempting to copy files, software or click and drag?
    Any other detail would be helpful.
    Allan

  • Creating variables in Process Flows and using thse variables in the filter

    Hi,
    I am new to OWB and in learing stage. Need to information.
    *1. as to how pass/create/use variables to OWB mapping ?*
    *2. Creating variables in Process Flows and using thse variables in the filter operator of the OWB mapping?*
    *3. Other mechanisms of how to create/use variables within OWB mapping itself ?*
    can you please provide the above details and guide me / help me in this regard.
    Thanks,
    skms.

    1. Add parameters to your mapping using the MAPPING INPUT PARAMETER from the pallette.
    2. Add parameters to the START operator in the process flow. Bind the process flow parameter to the Mapping parameter.
    3. May be appropriate to use CONSTANTS instead of parameters.
    Regards
    Si

Maybe you are looking for