SQL Server Agent Jobs Statistics

  • Comments posted to this topic are about the item SQL Server Agent Jobs Statistics

  • Does not even compile

  • vesa.juvonen (10/11/2013)


    Does not even compile

    I've copied and pasted the script verbatim and was successful in executing on a SQL 2000 server against the msdb database.

  • There is a small bug in the script :hehe: . Updated script will be published soon.

  • Thanks for the script.

  • The script is not working on SSMS 2016

  • francesco.mantovani - Wednesday, July 26, 2017 4:43 PM

    The script is not working on SSMS 2016

    It looks like you are in master when you are executing the script. You would need to be in msdb.

    Sue

  • Sue_H - Wednesday, July 26, 2017 5:40 PM

    francesco.mantovani - Wednesday, July 26, 2017 4:43 PM

    The script is not working on SSMS 2016

    It looks like you are in master when you are executing the script. You would need to be in msdb.

    Sue

    Yes, you were right, I was in a Master but then run the same script on a database and I received the same error

  • francesco.mantovani - Wednesday, July 26, 2017 5:47 PM

    Yes, you were right, I was in a Master but then run the same script on a database and I received the same error

    I can get the error too if I'm not in msdb. The table is in the msdb databse. That is the database you need to be in when you execute it. At the beginning of the script, before the select, add the following before the select and then try executing it. It's doesn't pull all of the information correctly but it should run:

    USE msdb
    go

    Sue

  • Thank you

    USE msdbUSE msdb

    go
    made the trick.

    For make it easy to use I added after SELECT

    DECLARE @DateFrom char(8) = '20170723' -- Set your start day range

    DECLARE @DateTo char(8) = '20170725'-- Set your end day range

    By the way I have uncommented, edited and added to the GROUP BY

    sJobHis.run_time AS [Running_Time],

    sJobHis.run_duration AS [Running_Duration],

    But the result is unclear and not easy to understand. I mean the script is awesome but it doesn't show me the big picture:

    Wouldn't be easier to show date like 'yyyy/mm/dd' and time like 'hh/mm/ss'?
    Can you help me do that?

  • That actually comes up fairly often - needing to change the integers to dates and times when querying job tables.
    There are quite a few posts up here for that - try referring to this one:
    Convert integer date to datetime

    Sue

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply