B
bmiller3419
Guest
I have a schedule of recurring "programs" that I would like to create a list from a database. The programs need to be placed into multiple time-slots (by weekday) and repeat every week. The database has two tables:
tblProgram lists the program title and program type. It is connected via one-many relationship to tblSchedule. tblSchedule lists has multiple records for each program listing the day of the week, start and end time the program occurs.
Here is the database structure (abridged):
tblProgram
- programid
- programtitle
- programtype: recurring or onetime
- startdate: date to start program repeat
- recurringenddate: program repeat expires
tblSchedule
- scheduleid
- programid
- weekday
- starttime
- endtime
Here is some sample data for "program1":
tblProgram:
programid title startdate enddate programtype
1 Program1 1/1/2004 1/1/2005 recurring
tblSchedule:
programid scheduleid weekday starttime endtime
1 7 2 1:00 PM 2:00 PM
1 8 3 1:00 PM 2:00 PM
1 9 4 1:00 PM 2:00 PM
1 10 5 1:00 PM 2:00 PM
1 11 6 1:00 PM 2:00 PM
Note: the start and the end date are for making programs effective or expired, it is not necessarily the first day the program appears.
Putting a query together that lists the program title along with all the times for a certain weekday is simple.
SELECT programtitle, weekday, starttime, endtime FROM tblProgram INNER JOIN tblSchedule ON tblProgram.programid = tblSchedule.programid ORDER BY starttime;
Here is some sample data for Thursday (5):
title weekday starttime end time
Program1 5 9:00 AM 10:00 AM
Program2 5 10:00 AM 11:00 AM
Program3 5 11:00 AM 1:00 PM
Program4 5 1:00 PM 2:00 PM
Program5 5 2:00 PM 3:00 PM
Program6 5 3:00 PM 4:00 PM
Here is the challenge!
There is "Progam Special" that needs to be added to the database. It's start and end times overlap other programs. It's a one-time, non-recurring program that needs to "pre-empt" any other recurring programs. For exmaple, Program 4 starts at 1:00 and ends at 2:00, Program 5 starts at 2:00 and ends at 3:00. "Program Special" occurs once on a certain week, starts at 1:30 and ends at 2:30.
Here is "ProgramSpecial"s data:
tblProgram:
programid title startdate enddate programtype
7 ProgramSpecial 10/28/04 10/28/04 one-time
tblSchedule:
programid scheduleid weekday starttime endtime
7 80 5 1:30 PM 2:30 PM
How do I create a query that inserts "Program Special" into the list?
title weekday starttime end time
Program1 5 9:00 AM 10:00 AM
Program2 5 10:00 AM 11:00 AM
Program3 5 11:00 AM 1:00 PM
Program4 5 1:00 PM 1:30 PM
ProgramSpecial 5 1:30 PM 2:30 PM
Program5 5 2:30 PM 3:00 PM
Program6 5 3:00 PM 4:00 PM
tblProgram lists the program title and program type. It is connected via one-many relationship to tblSchedule. tblSchedule lists has multiple records for each program listing the day of the week, start and end time the program occurs.
Here is the database structure (abridged):
tblProgram
- programid
- programtitle
- programtype: recurring or onetime
- startdate: date to start program repeat
- recurringenddate: program repeat expires
tblSchedule
- scheduleid
- programid
- weekday
- starttime
- endtime
Here is some sample data for "program1":
tblProgram:
programid title startdate enddate programtype
1 Program1 1/1/2004 1/1/2005 recurring
tblSchedule:
programid scheduleid weekday starttime endtime
1 7 2 1:00 PM 2:00 PM
1 8 3 1:00 PM 2:00 PM
1 9 4 1:00 PM 2:00 PM
1 10 5 1:00 PM 2:00 PM
1 11 6 1:00 PM 2:00 PM
Note: the start and the end date are for making programs effective or expired, it is not necessarily the first day the program appears.
Putting a query together that lists the program title along with all the times for a certain weekday is simple.
SELECT programtitle, weekday, starttime, endtime FROM tblProgram INNER JOIN tblSchedule ON tblProgram.programid = tblSchedule.programid ORDER BY starttime;
Here is some sample data for Thursday (5):
title weekday starttime end time
Program1 5 9:00 AM 10:00 AM
Program2 5 10:00 AM 11:00 AM
Program3 5 11:00 AM 1:00 PM
Program4 5 1:00 PM 2:00 PM
Program5 5 2:00 PM 3:00 PM
Program6 5 3:00 PM 4:00 PM
Here is the challenge!
There is "Progam Special" that needs to be added to the database. It's start and end times overlap other programs. It's a one-time, non-recurring program that needs to "pre-empt" any other recurring programs. For exmaple, Program 4 starts at 1:00 and ends at 2:00, Program 5 starts at 2:00 and ends at 3:00. "Program Special" occurs once on a certain week, starts at 1:30 and ends at 2:30.
Here is "ProgramSpecial"s data:
tblProgram:
programid title startdate enddate programtype
7 ProgramSpecial 10/28/04 10/28/04 one-time
tblSchedule:
programid scheduleid weekday starttime endtime
7 80 5 1:30 PM 2:30 PM
How do I create a query that inserts "Program Special" into the list?
title weekday starttime end time
Program1 5 9:00 AM 10:00 AM
Program2 5 10:00 AM 11:00 AM
Program3 5 11:00 AM 1:00 PM
Program4 5 1:00 PM 1:30 PM
ProgramSpecial 5 1:30 PM 2:30 PM
Program5 5 2:30 PM 3:00 PM
Program6 5 3:00 PM 4:00 PM