dbTalk Databases Forums  

Querying for Third Shift

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss Querying for Third Shift in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
dmeiser
 
Posts: n/a

Default Querying for Third Shift - 07-12-2006 , 08:50 AM






Hello all:

I need to query a table for events that happen on third shift ( 11 PM
to 7 AM ) in a date range. In the past, I've only needed to query for
one night, but I now need to query for 14 days. Normally, I would say
WHEN Col BETWEEN TimeStamp1 And TimeStamp2, but obviously that won't
work in this case.

For first shift I was able to do WHEN DateCol BETWEEN Date1 And Date2
AND WHEN TimeCol BETWEEN Time1 AND Time2, but for third shift this
obviously won't work.

I could use two different queries and, for third shift, say WHEN ...
AND TimeCol BETWEEN Time1 AND 11:59:59 and then UNION it with WHEN
TimeCol BETWEEN 00:00:00 AND Time2. However, since this will be linked
into an MS Access report, I'd prefer not to have to maintain two
different reports and copy the report back and forth if I make a change
to the SQL or report layout.

Is there any way to do this without either a UNION query or an SQL
function?

Thanks for any help.


Reply With Quote
  #2  
Old   
Sathyaram Sannasi
 
Posts: n/a

Default Re: Querying for Third Shift - 07-12-2006 , 09:19 AM






How about

col between timestamp1 and timestamp2 and (time(col) > 2300 or
time(col) < 0700)

Sathyaram


Reply With Quote
  #3  
Old   
dmeiser
 
Posts: n/a

Default Re: Querying for Third Shift - 07-12-2006 , 10:07 AM



I thought this might work, but then I realized I had left something
out: I'm selecting a maximum and minimum time for an event for each
business day in the two week period.

Since our business day starts the previous day at about 11:00 PM
(really, whenever third shifters start), the minimum time for that
business day might be 11:15 PM the previous day, while the maximum time
might be 6:30 AM on the actual day. The whole reason behind getting
the maximum and minimum times is to figure out the time difference
between them.

Perhaps I do need two queries: one with performing a union between
times > 11:00 PM Times < 7:00 AM and the second for day shifters?

Sathyaram Sannasi wrote:
Quote:
How about

col between timestamp1 and timestamp2 and (time(col) > 2300 or
time(col) < 0700)

Sathyaram


Reply With Quote
  #4  
Old   
ChrisC
 
Posts: n/a

Default Re: Querying for Third Shift - 07-12-2006 , 11:29 AM




dmeiser wrote:
Quote:
...
Since our business day starts the previous day at about 11:00 PM
(really, whenever third shifters start), the minimum time for that
business day might be 11:15 PM the previous day, while the maximum time
might be 6:30 AM on the actual day. The whole reason behind getting
the maximum and minimum times is to figure out the time difference
between them.

If you have a timestamp column containing this information (as opposed
or in addition to a broken out date and time columns), then Sathyaram's
solution will work as he wrote it - the first part of the query can
take care of the overlapping dates. If the dates are broken out, then
the union might work best.

If you have timestamps, you can rewrite Sathyaram's query to do this by
using between, too. Use:

col between timestamp1 and timestamp2 and (time(col + 8 hours) between
0700 and
and 1500)

-Chris



Reply With Quote
  #5  
Old   
dmeiser
 
Posts: n/a

Default Re: Querying for Third Shift - 07-20-2006 , 08:08 AM



I realized how to do this after some time by doing the following:

Select column1, sum(column2), Max(Time), Min(Time), From (
Select column1, column2, time from file where time <= midnight
Union Select column1, column2, time from file where time >= midnight
and time <= 7:00 AM
) Group By column1 Order by column1


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.