>> My "events" table contains eventtitle, date,starthour and endhour.
Hours are numbered from "0" to "23". <<
I would not do it that way; you are splitting up durations that you have
to re-assemble later. Keep the temporal data in proper units.
CREATE TABLE Events
(event_title VARCHAR(50),
start_time DATETIME NOT NULL
CHECK (DATEPART(MI, start_time) IN (00, 15, 30, 45)),
end_time DATETIME NOT NULL
CHECK (DATEPART(MI, end_time) IN (00, 15, 30, 45)),
CHECK (start_time < end_time),
PRIMARY KEY (start_time, end_time));
>> I also have a lookup table of the "hours of the day" with which I did
a JOIN to include the "missing" hours (where there were no events -
making a query that returned events for each hour and nulls for each
hour that had no event scheduled for it. But this makes too many "blank"
rows, which is part of the clutter to which I referred. <<
Keeping with the idea of temporal data being in tact
CREATE TABLE Calendar
(cal_date DATETIME NOT NULL PRIMARY KEY);
>> need to calculate one or more "spans" that contain contiguous groups
of start/end times. <<
I am not sure what you mean by that. Queries using the above model
will make a lot of use of things like this
SELECT C1.cal_date,
COUNT(E1.event_titles) AS nbr_things_to_do
FROM Events AS E1, Calendar AS C1
WHERE C1.cal_date BETWEEN E1.start_time AND E1.end_time
GROUP BY C1.cal_date;
Longer spans are determined by not having a cal_date for which a
(start_time, end_time) pair exists within its range -- a gap.
--CELKO--
===========================
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are.
*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!