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

  • Home
  • SEARCH
  • 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 8446029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:49:05+00:00 2026-06-10T09:49:05+00:00

Hard to put my question into a title. What I am looking for is

  • 0

Hard to put my question into a title. What I am looking for is a way to see which tasks were scheduled to run in the past 15 minutes.

I currently have a table that shows the window that a task should run and how often it should be kicked off within that window. However, I have no experience with this type of query. Hopefully somebody can help out a bit. I should also say that I’d like to do this without creating extra tables

Schedule Table

| taskID | startTime | endTime | everyMinutes |
|________|___________|_________|______________|
| 135467 |    8:00   |  20:00  |      15      |
| 675314 |    7:15   |  13:45  |      30      |

For example, in the above table, if the time was 9:18, the query would return both tasks

| taskID | scheduledTime|
|________|______________|
| 135467 |     9:15     |
| 675314 |     9:15     |

Where as if it was ran at 9:35 the query would only return 1 result

| taskID | scheduledTime|
|________|______________|
| 135467 |     9:30     |
  • 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-10T09:49:07+00:00Added an answer on June 10, 2026 at 9:49 am

    You could use a numbers table to expand the Schedule table into a series of taskID, scheduledTime rows, then filter the rows to return only those that have scheduledTime within the last 15 minutes:

    WITH expanded AS (
      SELECT
        s.taskID,
        scheduledTime = DATEADD(MINUTE, s.everyMinutes * n.N, s.startTime)
      FROM Schedule s
      INNER JOIN Numbers n
      ON n.N BETWEEN 0 AND DATEDIFF(MINUTE, s.startTime, s.endTime) / s.everyMinutes
    )
    SELECT e.*
    FROM expanded e
    CROSS APPLY (SELECT CAST(GETDATE() AS time)) x (now)
    WHERE e.scheduledTime BETWEEN DATEADD(MINUTE, -15, x.now) AND x.now
    ;
    

    You can try this query, as well as play with it, at SQL Fiddle.

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

Sidebar

Related Questions

It's hard to put this into the title, so let me explain. I have
I really had a hard time knowing what words to put into the title
I'm sorry for ambiguous title, but this question is hard for me to put
Hard to come up with a proper title for this problem. Anyway... I'm currently
I'm currently going through the book Learning Python The Hard Way, and I'm trying
How can I put a hard disk drive in stand-by or sleep mode in
I have hard-coded data into a .jsp file. What I want to do is
This question may have been asked before, but I'm starting to get into game
yet another PHP question which I am stuck on, so here is what im
I tagged this question as javascript because even though I currently wrote this in

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.