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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:57:02+00:00 2026-06-05T05:57:02+00:00

I am working on an app that has some scheduling functionality. As part of

  • 0

I am working on an app that has some scheduling functionality. As part of this, I need to select a list of people and whether or not they have have something scheduled in a certain period of the week.

The number of periods in the week are variable so they are stored in a reference table, for example:

Period Reference Table

id   name       start                 end                     day
------------------------------------------------------------------
1    Morning    1900-01-01 4:00:00    1900-01-01 11:00:00     MON
2    Afternoon  1900-01-01 14:00:00   1900-01-01 20:00:00     MON  
3    Night      1900-01-01 20:00:00   1900-01-01 24:00:00     MON  
4    Morning    1900-01-01 4:00:00    1900-01-01 11:00:00     TUE
5    Afternoon  1900-01-01 14:00:00   1900-01-01 20:00:00     TUE  
6    Night      1900-01-01 20:00:00   1900-01-01 24:00:00     TUE 

I also have a “person reference” table and a “person schedule” table.
The “person schedule” table only stores a record if a person has something scheduled in a period, here is a simplified example:

Person Schedule Table

id    person_id     period_id
------------------------------
1     1             2
2     1             3
3     2             2
4     2             3
5     2             4

Now I need to select from these three tables a full list of periods for each person and whether they have a schedule record in the period or not (1 or 0). In other words, I need to get this resultset for the example data above:

person_id     period_id     is_scheduled
----------------------------------------
1             1             0
1             2             1
1             3             1
1             4             0
1             5             0
1             6             0
2             1             0
2             2             1
2             3             1
2             4             1
2             5             0
2             6             0

Is it possible to do this with a select statement without getting into dynamic SQL?

This is all done using SQL Server 2000

  • 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-05T05:57:05+00:00Added an answer on June 5, 2026 at 5:57 am
    SELECT 
      people.person_id, period_id = periods.id, is_scheduled = CASE
      WHEN schedule.person_id IS NOT NULL THEN 1 ELSE 0 END
    FROM dbo.[period reference table] AS periods
    CROSS JOIN 
    (
      SELECT person_id 
        FROM dbo.[person schedule table] 
        GROUP BY person_id
    ) AS people
    LEFT OUTER JOIN 
      dbo.[person schedule table] AS schedule
      ON people.person_id = schedule.person_id
      AND periods.id = schedule.period_id
    ORDER BY 
      people.person_id, p.id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an app that has some forms that are contained within a
I am working on an iPhone app that has to post some data to
I am working on a windows app that has the functionality to set overlay
I am working on an App that has a page with a listview and
I'm working on a PHP app that has several objects that can be commented
I am working on an android app that has a database in which one
I'm working on a rewrite of an app that has three categories of users
I am working on a web-app system that has multiple apps, each with a
A client im working for has created a web app that uses a password
I am working on a simple app tab-bar based application that has two views.

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.