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 1075855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:19:48+00:00 2026-05-16T21:19:48+00:00

I have a table that contains a list of tasks; TableName: Tasks. Fields: (ID

  • 0

I have a table that contains a list of tasks;

TableName: Tasks. Fields: (ID Int, Description nvarchar)

The tasks are completed daily and are logged in a table like follows;

TableName TasksDone. Fields: (TaskID Int, TaskDate DateTime)

I need to have a query that runs for a date range and shows the tasks that were NOT done (do not exist in the TasksDone table) for every date in the range.

I hope that makes sense…
Thanks for any help.

  • 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-05-16T21:19:48+00:00Added an answer on May 16, 2026 at 9:19 pm

    You will need a numbers or calendar table to make things easy, or we can simulate one if the range is small. Is the TaskDate a plain date, or does it have a time component also?

    Basic plan of attack is:

    declare @StartDate datetime
    declare @EndDate datetime
    
    /* Set @StartDate and @EndDate to represent the range */
    
    with Digits as (
        select 0 as d union all select 1 union all select 2 union all select 3 union all select 4 union all
        select 5 union all select 6 union all select 7 union all select 8 union all select 9
    ), Numbers as (
        select (D1.d * 100) + (D2.d * 10) + D3.d as n
        from Digits D1,Digits D2,Digits D3
    ), TaskDates as (
        select
            t.TaskID,
            DATEADD(day,n.n,@StartDate) as TaskDate
        from
            Tasks t
                inner join
            Numbers n
                on
                    DATEADD(day,n.n,@StartDate) <= @EndDate
    )
    select
        *
    from
        TaskDates td1
            left join
        TasksDone td2
            on
                td1.TaskID = td2.TaskID and
                DATEDIFF(day,td1.TaskDate,td2.TaskDate) = 0
    where
        td2.TaskID is null
    

    The first two CTEs build a small numbers table, the 3rd CTE constructs a set of TaskIDs and Dates within the required range. The final select matches theses against the TasksDone table, and then discards those rows where a match is found. If TasksDone.TaskDate is a plain date (no time component) and @StartDate is also with no time component, then you can ditch the DATEDIFF and just use td1.TaskDate = td2.TaskDate.

    If you need a large range (above can cover ~3 years), I’d suggest building a proper number table or calendar table

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

Sidebar

Related Questions

Here is my situation: I have one table that contains a list of drugs
I have a table that contains multiple dropdown menus for a list of profile
I have a mysql table (table-A) that contains a list of unique product ids.
I have a DB table that contains a comma separated list of ID's (ints)
I have a table that contains the following columns: ID int, DISTANCE float, EVENT
I have a table that contains a list of machines that are loaned out
I have a table that contains a list of EquipmentIDs and another table that
I have a table called Order_List that contains a list of orders. Each column
I have a table that contains events, to list these events I loop through
Suppose I have a table that contains a list of ids pointing to table

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.