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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T17:01:58+00:00 2026-05-14T17:01:58+00:00

I need some T-SQL that will show missing records. Here is some sample data:

  • 0

I need some T-SQL that will show missing records.

Here is some sample data:

Emp 1
01/01/2010
02/01/2010
04/01/2010
06/01/2010

Emp 2
02/01/2010
04/01/2010
05/01/2010
etc...

I need to know

Emp 1 is missing 
03/01/2010
05/01/2010

Emp 2 is missing 
01/01/2010
03/01/2010 
06/01/2010

The range to check will start with todays date and go back 6 months.

In this example, lets say today’s date is 06/12/2010 so the range is going to be 01/01/2010 thru 06/01/2010.

The day is always going to be the 1st in the data.

Thanks a bunch. 🙂

Gerhard Weiss
Secretary of Great Lakes Area .NET Users Group
GANG Upcoming Meetings | GANG LinkedIn Group

  • 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-14T17:01:58+00:00Added an answer on May 14, 2026 at 5:01 pm

    Try This:

    DECLARE @Employees table (DateOf datetime, EmployeeID int)
    INSERT @Employees VALUES ('01/01/2010',1)
    INSERT @Employees VALUES ('02/01/2010',1)
    INSERT @Employees VALUES ('04/01/2010',1)
    INSERT @Employees VALUES ('06/01/2010',1)
    INSERT @Employees VALUES ('02/01/2010',2)
    INSERT @Employees VALUES ('04/01/2010',2)
    INSERT @Employees VALUES ('05/01/2010',2)
    
    --I was unsure of the data in the question
    --this gives first day of each month for last six months
    DECLARE @StartDate datetime
           ,@EndDate datetime
    SELECT @StartDate=DATEADD(month,-6,DATEADD(month,DATEDIFF(month,0,GETDATE()),0) )
          ,@EndDate=GETDATE()
    
    ;with AllDates AS
    (
        SELECT @StartDate AS DateOf
        UNION ALL
        SELECT DateAdd(month,1,DateOf)
            FROM AllDates
        WHERE DateOf<@EndDate
    )
    SELECT
        dt.DateOf,dt.EmployeeID
        FROM (SELECT DISTINCT
                  a.DateOf,e.EmployeeID
              FROM AllDates                    a
                  CROSS JOIN (SELECT DISTINCT EmployeeID FROM @Employees) e
            ) dt
            LEFT OUTER JOIN @Employees ee ON dt.EmployeeID=ee.EmployeeID AND dt.DateOf=ee.DateOf
        WHERE ee.EmployeeID IS NULL
        ORDER BY dt.EmployeeID,dt.DateOf
    

    OUTPUT:

    DateOf                  EmployeeID
    ----------------------- -----------
    2009-10-01 00:00:00.000 1
    2009-11-01 00:00:00.000 1
    2009-12-01 00:00:00.000 1
    2010-03-01 00:00:00.000 1
    2010-05-01 00:00:00.000 1
    2009-10-01 00:00:00.000 2
    2009-11-01 00:00:00.000 2
    2009-12-01 00:00:00.000 2
    2010-01-01 00:00:00.000 2
    2010-03-01 00:00:00.000 2
    
    (10 row(s) affected)
    

    this will do every day for last six months, just incorporate this in the above if that is what you want:

    DECLARE @StartDate datetime
           ,@EndDate datetime
    SELECT @StartDate=DATEADD(month,-6,GETDATE())
          ,@EndDate=GETDATE()
    ;with AllDates AS
    (
        SELECT @StartDate AS DateOf
        UNION ALL
        SELECT DateOf+1
            FROM AllDates
        WHERE DateOf<@EndDate
    )
    SELECT * FROM AllDates
    --OPTION (MAXRECURSION 500) --uncomment and increase if the date range needs more rows
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 436k
  • Answers 436k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer See Sanjay's comment above. May 15, 2026 at 4:02 pm
  • Editorial Team
    Editorial Team added an answer 'Rank' is the frequency of a term within a field.… May 15, 2026 at 4:02 pm
  • Editorial Team
    Editorial Team added an answer Exactly. But don't rely on this behavior. May 15, 2026 at 4:02 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.