I've been scratching my head on this for quite awhile and it has me stumped.
I hope to define a query which I can use to fill a "day planner" type of
calendar. Although I've see a lot of these, only one has had what I think
is a really nice feature - it collected into groups all events that
overlapped into contiguous blocks of time. The net result of this is that
it becomes possible to output a calendar (html table) that is much less
cluttered. So I want to use this same idea for my own little project.
The trick is that events may (or may not) start and end such that they
overlap (completely or only at one end). I only am concerned with events on
a given day.
My "events" table contains eventtitle, date,starthour and endhour. Hours
are numbered from "0" to "23". 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.
I've been able to construct queries that work in some cases, but not all.
I've reread my copy of Celko's SQL For Smarties and came close, but no
cigar. Where he discusses hotels and room-nights is part of the solution I
needed, but my need goes beyond that quite a bit.
Basically, I need to calculate one or more "spans" that contain contiguous
groups of start/end times. By knowing the number of hours spanned, I can
then use that for a <TD rowspan='n'> to collect my data like I want.
I seem to keep hitting all around the solution. Maybe there isn't one (that
is purely a SQL solution). Or maybe I'm just looking at the problem the
wrong way.
So I thought I'd see if anyone here might point me in the right (or at least
"new") direction. I've been looking at this for so long, I'm probably
overlooking some simple and obvious trick to do this. Or maybe I'll get
lucky and someone has seen or done exactly this already and can provide a
solution?
Incidentally, I've avoided utilizing a stored procedure or making a number
of temp tables to collect intermediate results, as I might need to port this
to a "dumb" database that does not provide such facilities. Maybe that's
impractical?
thanks in advance,
-- 3 4508
Herb Kauhry (ti****@tulips. me) writes: My "events" table contains eventtitle, date,starthour and endhour. Hours are numbered from "0" to "23". 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.
I'm afraid that I have to meet your question with a standard reply.
Please post the following:
o CREATE TABLE statement your table(s).
o INSERT statements with sample data.
o Expected output from that data.
The reason for this only from a narrative is difficult to feel
certaintity that one has full understanding of what you are asking
for. Also, by providing the above, you can also get a tested solution.
So while this requires you do some more work, you save time in the
end.
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
>> 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_d o
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! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ravi Shankar |
last post by:
Hi all,
I have a calendar application( like Microsoft Outlook) writtn in
Java.Whenever an event is created, we can set SMS/EMAIL notification. Hence
when an event is created, I am storing that event info and notification time
into a database.Now the notification can be ranging from 5 minutes to say
one day.Hence I need to query the databse every 5 minutes and fetch the data
and do send the notification directly. I understand that such a...
|
by: Webby |
last post by:
I've decided after several failed attempts this is too difficult to do
on my own. I know it's been done before and a tutorial or code must
by lying around somewhere.
I have a Weekly Calendar
It's in a table with 7 columns and 22 rows
Across the top I have Monday thru Sunday
|
by: Jose |
last post by:
I want to query my outlook calendar and display the meetings and appointments
in the web form.
How this can be achieved? Please help.
|
by: Rado |
last post by:
Hello.
I've got one question. Could anybody advise me?
I would like to make somethink such as MS outlook 2003 daily calendar.So I
click on something hour and program add there task.When I click on the same
hour, program detect if is there any other task, If yes, program make this
task smaller and add new task.
I need 't help how can I programm it, but I need axiom/tenet/ How Can I do
it. I think: How program detect if on the place where...
|
by: amerar |
last post by:
Hi All,
I'm looking for a special Javascript calendar. My client will be
creating a weekly schedule via an HTML form, for the current week only.
So, I want a calendar which allows him to choose the weekday, and the
hour & minute. I do not want a calendar where he can scroll month to
month......since this is for the current week only......
Any suggestions?
| |
by: Jim Michaels |
last post by:
SELECT id,name, prj,SUM(TIMEDIFF(end_time,start_time)) AS elapsed
FROM work
group by name,prj;
The problem is, I need elapsed in a datetime format, and SUM truncates to
integer hours.
Is there no way to do this?
I just want the group sums as hours, minutes, dats, months, years.
|
by: labanino |
last post by:
Hello, I'm new to xml. This is what I'm trying to do! I have an html doc. with a calendar in it and a xml file attached to it with information for each day of the month. I need, for example, after clicking day 1 in the calendar, all the data for that day in my xml file to show in an external file. I don't know how to do queries and stuff like that. Any help, please!
|
by: =?Utf-8?B?R2lkaQ==?= |
last post by:
Hi,
I'm trying to build a Calendar (outlook style) with C#.
When I just thought i almost finished, i found out that I've few problems.
I want my calndar will have the ability to show few appointments at the same
time (meaning that person 1 has meeting from 10-12 and person 2 has meeting
from 10:30-13:00), I used User Control to crate a label that presnets the
task, and created it for each hour, so actually i've 34 lables when actually
i...
|
by: Erik Lupien |
last post by:
Could someone, anyone, help me and compose a VBA script for me to use with MS Access?
I know nothing about MS Access of VBA scripting for it but really need some help.
I have an MS Access database on a server at work that records employee sick leave, by hour, by date.
I need to know the number of occurences when employees were gone on sick leave for 10 or more consecutive work days, during a calendar year that starts on Jan 1 and ends...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |