Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7979403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:46:10+00:00 2026-06-04T09:46:10+00:00

The Scenario There are certain SQL Agent Jobs that are scheduled to run every

  • 0

The Scenario

There are certain SQL Agent Jobs that are scheduled to run every few minutes throughout the day.

There are legitimate times when it will miss its next schedule because it’s still running from the previous schedule.

Every once and a while, a job might ‘hang’. This doesn’t produce a failure (since the job hasn’t stopped yet). When this happens, the job can be manually stopped and works fine the next time it runs. It’s designed to pick back up where it left off.

What’s the most efficient way…?

I’d like a way to determine how long (in seconds) a SQL Agent Job named ‘JobX’ is currently running. If it isn’t currently running, we can just return zero.

This way, I can stop the job if it has been running for an amount of time beyond a certain threshold.

I assume that a combination of xp_sqlagent_enum_jobs and sysjobhistory could be used, but I’m curious if there are better solutions out there… and can hopefully benefit from the obstacles the rest of you have already run into and worked around.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:46:12+00:00Added an answer on June 4, 2026 at 9:46 am

    This solution would work:

    SELECT DATEDIFF(SECOND,aj.start_execution_date,GetDate()) AS Seconds
    FROM msdb..sysjobactivity aj
    JOIN msdb..sysjobs sj on sj.job_id = aj.job_id
    WHERE aj.stop_execution_date IS NULL -- job hasn't stopped running
    AND aj.start_execution_date IS NOT NULL -- job is currently running
    AND sj.name = 'JobX'
    and not exists( -- make sure this is the most recent run
        select 1
        from msdb..sysjobactivity new
        where new.job_id = aj.job_id
        and new.start_execution_date > aj.start_execution_date
    )
    

    This a more general check dependent on system tables. If you’d prefer a custom route, you could have the job insert into a job log table you created instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario : There is this online questionaire that will be filled in by various
Are there any security exploits that could occur in this scenario: eval(repr(unsanitized_user_input), {__builtins__: None},
In my project there is a scenario that user will log in -> browse
I am using Hibernate in my project and there is a certain scenario where
There is a scenario, I have a SQL Server with tones of data in
Scenario: I have an application (C#) that expects a SQL database and login, which
Here's the scenario: small closed-source project that needs to share a certain model across
I run an in-house application, programmed with visual studio 2008, that uses SQL Server
In SQL Server, is there any easy way to achieve below scenario? In one
In our build there are certain scenarios that fail for reasons which are out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.