Need a date query hero

J

John G

I have a table that has 5 fields:
ID, AutoNumber
Ticket, Number
Techs, Number
Start, Date/Time
Stop, Date/Time

I built 3 seperate queries that output the below information

qryJob:
ID Ticket# Techs Start Stop TotalMH
1 A123 1 8/12/05 9:00 8/12/05 11:00 2.00
2 A123 2 8/12/05 9:00 8/12/05 12:00 6.00
3 A123 1 8/12/05 14:00 8/12/05 18:00 2.00
4 A123 1 8/13/05 9:00 8/13/05 11:00 2.00

I built another query that calculates the Total Man Hours for each ticket

qryJobMH:
Ticket# TotalMH
A123 14.00

I also have yet another query that calculates the total elapsed time

qryJobElpsd:
Ticket# TotalElpsd
A123 26.00

I REALLY REALLY NEED HELP WITH a query that will output the below information
Ticket# CrazyTotal
A123 9.00

This is essentially total elapsed time this ticket was being worked on.
Earliest start time on 8/12 is 9:00 and then the latest end time for that bit
of overlap is 12:00 which is 3 hours. Then we have a gap of 2 hours and work
again from 14:00 to 18:00 which is an additional 4. The next day we work from
9:00 to 11:00 which is another 2. Add them up and we get 9.00 hours.

Any takers?
TIA!!!!

John G.
 
J

John G

Sorry, I just realized that I posted some flawed math...the TotalMH for ID 3
is supposed to be 4.00 and not 2.00. So the CrazyTotal would need to be
11.00, not 9.00
:)
 
M

Michel Walsh

Hi,



Always store the date with the time, and then it seems to be a matter to
subtract SUMs:

SELECT id, SUM(Stop)-SUM(Start) As SumOfElapsed
FROM myTable
WHERE Not ( Stop IS NULL)
GROUP BY id



The WHERE clause removes records with incomplete (utilization) information.


Hoping it may help
Vanderghast, Access MVP
 
J

John G

Thanks Michel,

Thank you for the quick reply. I am storing the dates with the times.
The example data was part of a query with an added calculated field to give
the TotalMH. TotalMH is
Format(((DateDiff("n",[Start],[Stop])/60)*[Techs]),"Fixed"). This is without
grouping.
Then in qryJobMH I grouped by Ticket# and then used
Sum(IIf(qryJob!TotalMH<>"",qryJob!TotalMH,"0.00")) AS TotalMH (*I should
probably use a different name like TotalJobMH) for that query.

I'm pretty new at this and am not really sure if the query you provided will
be able to do what I need it to. For instance when I ran it and say increased
ID 2 to have 9 Techs the total should be 27 and the query returned only
21:00. Do I need to convert the returned data before I format it for display?

Thanks for the help!
 
M

Michel Walsh

Hi,


You are not supposed to format the data, BEFORE making the computation,
no.

The solution was based on the fact that:

L1-a1 + L2-a2 + L3-a3 + ..... + L9-a9


(ie, leaving minus arriving ) is the same as


( L1 + L2 + L3 + .... + L9 ) - ( a1 + a2 + a3 + ... + a9 )

which is the same as


SUM(L) - SUM(a)


When you say it return 27 (hours) and return 21, are you sure it really
SHOULD return 27.


Now, if your data exceed 24 hour, you may get a result as 31st December
1899 01:00:00 instead of 25:00:00, as example. That, you have to format
to get 25:00:00 rather than this date.

Int( 1E-5 + 24 * x ) & Format( x, ":nn:ss")


for x a positive period of time interval should do the job.



Hoping it may help,
Vanderghast, Access MVP



John G said:
Thanks Michel,

Thank you for the quick reply. I am storing the dates with the times.
The example data was part of a query with an added calculated field to
give
the TotalMH. TotalMH is
Format(((DateDiff("n",[Start],[Stop])/60)*[Techs]),"Fixed"). This is
without
grouping.
Then in qryJobMH I grouped by Ticket# and then used
Sum(IIf(qryJob!TotalMH<>"",qryJob!TotalMH,"0.00")) AS TotalMH (*I should
probably use a different name like TotalJobMH) for that query.

I'm pretty new at this and am not really sure if the query you provided
will
be able to do what I need it to. For instance when I ran it and say
increased
ID 2 to have 9 Techs the total should be 27 and the query returned only
21:00. Do I need to convert the returned data before I format it for
display?

Thanks for the help!

Michel Walsh said:
Hi,



Always store the date with the time, and then it seems to be a matter
to
subtract SUMs:

SELECT id, SUM(Stop)-SUM(Start) As SumOfElapsed
FROM myTable
WHERE Not ( Stop IS NULL)
GROUP BY id



The WHERE clause removes records with incomplete (utilization)
information.


Hoping it may help
Vanderghast, Access MVP
 
J

John G

Hi Michel, I apologize if I seem slow but I think my wires got crossed
somewhere and I explained what I was looking for poorly. What I am after is a
query that will take the date/times from the table below and treat the
overlapping date/times as one record with the earliest date/time and the
lastest date/time of the overlapping records combimed into one.

So the table looks exactly like this:
ID Ticket# Techs Start Stop
1 123 1 08/12/2005 8:00 08/12/2005 11:00
2 123 2 08/12/2005 9:00 08/12/2005 12:00
3 123 1 08/12/2005 14:00 08/12/2005 18:00
4 123 1 08/13/2005 9:00 08/13/2005 11:00

the query I'm looking for needs to return this:
Ticket# Start Stop Total
123 08/12/2005 8:00 08/12/2005 12:00 4.00 <---combination of overlapping
times ID 1 and 2
123 08/12/2005 14:00 08/12/2005 18:00 2.00
123 08/13/2005 9:00 08/13/2005 11:00 2.00

The total field I got using this expression which works just fine:
Total: Format(((DateDiff("n",[Start],[Stop])/60)),"Fixed")

I just can't for the life of me figure out how to combine the overlapping
times.

Any ideas?

Michel Walsh said:
Hi,


You are not supposed to format the data, BEFORE making the computation,
no.

The solution was based on the fact that:

L1-a1 + L2-a2 + L3-a3 + ..... + L9-a9


(ie, leaving minus arriving ) is the same as


( L1 + L2 + L3 + .... + L9 ) - ( a1 + a2 + a3 + ... + a9 )

which is the same as


SUM(L) - SUM(a)


When you say it return 27 (hours) and return 21, are you sure it really
SHOULD return 27.


Now, if your data exceed 24 hour, you may get a result as 31st December
1899 01:00:00 instead of 25:00:00, as example. That, you have to format
to get 25:00:00 rather than this date.

Int( 1E-5 + 24 * x ) & Format( x, ":nn:ss")


for x a positive period of time interval should do the job.



Hoping it may help,
Vanderghast, Access MVP



John G said:
Thanks Michel,

Thank you for the quick reply. I am storing the dates with the times.
The example data was part of a query with an added calculated field to
give
the TotalMH. TotalMH is
Format(((DateDiff("n",[Start],[Stop])/60)*[Techs]),"Fixed"). This is
without
grouping.
Then in qryJobMH I grouped by Ticket# and then used
Sum(IIf(qryJob!TotalMH<>"",qryJob!TotalMH,"0.00")) AS TotalMH (*I should
probably use a different name like TotalJobMH) for that query.

I'm pretty new at this and am not really sure if the query you provided
will
be able to do what I need it to. For instance when I ran it and say
increased
ID 2 to have 9 Techs the total should be 27 and the query returned only
21:00. Do I need to convert the returned data before I format it for
display?

Thanks for the help!

Michel Walsh said:
Hi,



Always store the date with the time, and then it seems to be a matter
to
subtract SUMs:

SELECT id, SUM(Stop)-SUM(Start) As SumOfElapsed
FROM myTable
WHERE Not ( Stop IS NULL)
GROUP BY id



The WHERE clause removes records with incomplete (utilization)
information.


Hoping it may help
Vanderghast, Access MVP


I have a table that has 5 fields:
ID, AutoNumber
Ticket, Number
Techs, Number
Start, Date/Time
Stop, Date/Time

I built 3 seperate queries that output the below information

qryJob:
ID Ticket# Techs Start Stop TotalMH
1 A123 1 8/12/05 9:00 8/12/05 11:00 2.00
2 A123 2 8/12/05 9:00 8/12/05 12:00 6.00
3 A123 1 8/12/05 14:00 8/12/05 18:00 2.00
4 A123 1 8/13/05 9:00 8/13/05 11:00 2.00

I built another query that calculates the Total Man Hours for each
ticket

qryJobMH:
Ticket# TotalMH
A123 14.00

I also have yet another query that calculates the total elapsed time

qryJobElpsd:
Ticket# TotalElpsd
A123 26.00

I REALLY REALLY NEED HELP WITH a query that will output the below
information
Ticket# CrazyTotal
A123 9.00

This is essentially total elapsed time this ticket was being worked on.
Earliest start time on 8/12 is 9:00 and then the latest end time for
that
bit
of overlap is 12:00 which is 3 hours. Then we have a gap of 2 hours and
work
again from 14:00 to 18:00 which is an additional 4. The next day we
work
from
9:00 to 11:00 which is another 2. Add them up and we get 9.00 hours.

Any takers?
TIA!!!!

John G.
 
M

Michel Walsh

Hi,


ah ah... Untested. The easiest solution I think that can solve that problem,
in general, requires temporary queries. The first one:


SELECT TicketID, Start As Timing, +1 As offset FROM myTable
UNION ALL
SELECT TicketID, Stop, -1 FROM myTable


Observe then that the Start time it to be kept if the running sum of the
offset (against the increasing value of Timing) is +1, and the Stop time is
to be kept if that same running sum correspond to a running sum of 0.


Get that running sum (query2):

SELECT a.TicketID, a.Timing, SUM(b.offset) As Running
FROM query1 As a INNER JOIN query1 As b
ON a.ticketID = b.ticketID AND b.Timing >= a.Timing
GROUP BY a.TickerID, a.Timing



So, we only have to pick the required values:


SELECT c.TicketID, c.start
FROM myTable As c INNER JOIN query2 as d
ON c.ticketID= d.ticketid AND c.start = d.timing
WHERE d.running = 1
ORDER BY c.TicketID, c.start


for the starting values, and



SELECT c.TicketID, c.stop
FROM myTable As c INNER JOIN query2 as d
ON c.ticketID= d.ticketid AND c.stop = d.timing
WHERE d.running = 0
ORDER BY c.TicketID, c.stop

supplies the stopping values, for the merged (or not merge) intervals.





Hoping it may help,
Vanderghast, Access MVP


John G said:
Hi Michel, I apologize if I seem slow but I think my wires got crossed
somewhere and I explained what I was looking for poorly. What I am after
is a
query that will take the date/times from the table below and treat the
overlapping date/times as one record with the earliest date/time and the
lastest date/time of the overlapping records combimed into one.

So the table looks exactly like this:
ID Ticket# Techs Start Stop
1 123 1 08/12/2005 8:00 08/12/2005 11:00
2 123 2 08/12/2005 9:00 08/12/2005 12:00
3 123 1 08/12/2005 14:00 08/12/2005 18:00
4 123 1 08/13/2005 9:00 08/13/2005 11:00

the query I'm looking for needs to return this:
Ticket# Start Stop Total
123 08/12/2005 8:00 08/12/2005 12:00 4.00 <---combination of overlapping
times ID 1 and 2
123 08/12/2005 14:00 08/12/2005 18:00 2.00
123 08/13/2005 9:00 08/13/2005 11:00 2.00

The total field I got using this expression which works just fine:
Total: Format(((DateDiff("n",[Start],[Stop])/60)),"Fixed")

I just can't for the life of me figure out how to combine the overlapping
times.

Any ideas?

Michel Walsh said:
Hi,


You are not supposed to format the data, BEFORE making the
computation,
no.

The solution was based on the fact that:

L1-a1 + L2-a2 + L3-a3 + ..... + L9-a9


(ie, leaving minus arriving ) is the same as


( L1 + L2 + L3 + .... + L9 ) - ( a1 + a2 + a3 + ... + a9 )

which is the same as


SUM(L) - SUM(a)


When you say it return 27 (hours) and return 21, are you sure it really
SHOULD return 27.


Now, if your data exceed 24 hour, you may get a result as 31st
December
1899 01:00:00 instead of 25:00:00, as example. That, you have to
format
to get 25:00:00 rather than this date.

Int( 1E-5 + 24 * x ) & Format( x, ":nn:ss")


for x a positive period of time interval should do the job.



Hoping it may help,
Vanderghast, Access MVP



John G said:
Thanks Michel,

Thank you for the quick reply. I am storing the dates with the times.
The example data was part of a query with an added calculated field to
give
the TotalMH. TotalMH is
Format(((DateDiff("n",[Start],[Stop])/60)*[Techs]),"Fixed"). This is
without
grouping.
Then in qryJobMH I grouped by Ticket# and then used
Sum(IIf(qryJob!TotalMH<>"",qryJob!TotalMH,"0.00")) AS TotalMH (*I
should
probably use a different name like TotalJobMH) for that query.

I'm pretty new at this and am not really sure if the query you provided
will
be able to do what I need it to. For instance when I ran it and say
increased
ID 2 to have 9 Techs the total should be 27 and the query returned only
21:00. Do I need to convert the returned data before I format it for
display?

Thanks for the help!

:

Hi,



Always store the date with the time, and then it seems to be a
matter
to
subtract SUMs:

SELECT id, SUM(Stop)-SUM(Start) As SumOfElapsed
FROM myTable
WHERE Not ( Stop IS NULL)
GROUP BY id



The WHERE clause removes records with incomplete (utilization)
information.


Hoping it may help
Vanderghast, Access MVP


I have a table that has 5 fields:
ID, AutoNumber
Ticket, Number
Techs, Number
Start, Date/Time
Stop, Date/Time

I built 3 seperate queries that output the below information

qryJob:
ID Ticket# Techs Start Stop TotalMH
1 A123 1 8/12/05 9:00 8/12/05 11:00 2.00
2 A123 2 8/12/05 9:00 8/12/05 12:00 6.00
3 A123 1 8/12/05 14:00 8/12/05 18:00 2.00
4 A123 1 8/13/05 9:00 8/13/05 11:00 2.00

I built another query that calculates the Total Man Hours for each
ticket

qryJobMH:
Ticket# TotalMH
A123 14.00

I also have yet another query that calculates the total elapsed time

qryJobElpsd:
Ticket# TotalElpsd
A123 26.00

I REALLY REALLY NEED HELP WITH a query that will output the below
information
Ticket# CrazyTotal
A123 9.00

This is essentially total elapsed time this ticket was being worked
on.
Earliest start time on 8/12 is 9:00 and then the latest end time for
that
bit
of overlap is 12:00 which is 3 hours. Then we have a gap of 2 hours
and
work
again from 14:00 to 18:00 which is an additional 4. The next day we
work
from
9:00 to 11:00 which is another 2. Add them up and we get 9.00 hours.

Any takers?
TIA!!!!

John G.
 
J

John G

Thanks for the quick reply and I apologize for my slow response. Sorry if I
appear ignorant but is what you have listed below 4 different queries that
need to be created seperately or just 1 large query? I guess I'm just not
sure how to put it together in access.
Thank you,
John G.

Michel Walsh said:
Hi,


ah ah... Untested. The easiest solution I think that can solve that problem,
in general, requires temporary queries. The first one:


SELECT TicketID, Start As Timing, +1 As offset FROM myTable
UNION ALL
SELECT TicketID, Stop, -1 FROM myTable


Observe then that the Start time it to be kept if the running sum of the
offset (against the increasing value of Timing) is +1, and the Stop time is
to be kept if that same running sum correspond to a running sum of 0.


Get that running sum (query2):

SELECT a.TicketID, a.Timing, SUM(b.offset) As Running
FROM query1 As a INNER JOIN query1 As b
ON a.ticketID = b.ticketID AND b.Timing >= a.Timing
GROUP BY a.TickerID, a.Timing



So, we only have to pick the required values:


SELECT c.TicketID, c.start
FROM myTable As c INNER JOIN query2 as d
ON c.ticketID= d.ticketid AND c.start = d.timing
WHERE d.running = 1
ORDER BY c.TicketID, c.start


for the starting values, and



SELECT c.TicketID, c.stop
FROM myTable As c INNER JOIN query2 as d
ON c.ticketID= d.ticketid AND c.stop = d.timing
WHERE d.running = 0
ORDER BY c.TicketID, c.stop

supplies the stopping values, for the merged (or not merge) intervals.





Hoping it may help,
Vanderghast, Access MVP


John G said:
Hi Michel, I apologize if I seem slow but I think my wires got crossed
somewhere and I explained what I was looking for poorly. What I am after
is a
query that will take the date/times from the table below and treat the
overlapping date/times as one record with the earliest date/time and the
lastest date/time of the overlapping records combimed into one.

So the table looks exactly like this:
ID Ticket# Techs Start Stop
1 123 1 08/12/2005 8:00 08/12/2005 11:00
2 123 2 08/12/2005 9:00 08/12/2005 12:00
3 123 1 08/12/2005 14:00 08/12/2005 18:00
4 123 1 08/13/2005 9:00 08/13/2005 11:00

the query I'm looking for needs to return this:
Ticket# Start Stop Total
123 08/12/2005 8:00 08/12/2005 12:00 4.00 <---combination of overlapping
times ID 1 and 2
123 08/12/2005 14:00 08/12/2005 18:00 2.00
123 08/13/2005 9:00 08/13/2005 11:00 2.00

The total field I got using this expression which works just fine:
Total: Format(((DateDiff("n",[Start],[Stop])/60)),"Fixed")

I just can't for the life of me figure out how to combine the overlapping
times.

Any ideas?

Michel Walsh said:
Hi,


You are not supposed to format the data, BEFORE making the
computation,
no.

The solution was based on the fact that:

L1-a1 + L2-a2 + L3-a3 + ..... + L9-a9


(ie, leaving minus arriving ) is the same as


( L1 + L2 + L3 + .... + L9 ) - ( a1 + a2 + a3 + ... + a9 )

which is the same as


SUM(L) - SUM(a)


When you say it return 27 (hours) and return 21, are you sure it really
SHOULD return 27.


Now, if your data exceed 24 hour, you may get a result as 31st
December
1899 01:00:00 instead of 25:00:00, as example. That, you have to
format
to get 25:00:00 rather than this date.

Int( 1E-5 + 24 * x ) & Format( x, ":nn:ss")


for x a positive period of time interval should do the job.



Hoping it may help,
Vanderghast, Access MVP



Thanks Michel,

Thank you for the quick reply. I am storing the dates with the times.
The example data was part of a query with an added calculated field to
give
the TotalMH. TotalMH is
Format(((DateDiff("n",[Start],[Stop])/60)*[Techs]),"Fixed"). This is
without
grouping.
Then in qryJobMH I grouped by Ticket# and then used
Sum(IIf(qryJob!TotalMH<>"",qryJob!TotalMH,"0.00")) AS TotalMH (*I
should
probably use a different name like TotalJobMH) for that query.

I'm pretty new at this and am not really sure if the query you provided
will
be able to do what I need it to. For instance when I ran it and say
increased
ID 2 to have 9 Techs the total should be 27 and the query returned only
21:00. Do I need to convert the returned data before I format it for
display?

Thanks for the help!

:

Hi,



Always store the date with the time, and then it seems to be a
matter
to
subtract SUMs:

SELECT id, SUM(Stop)-SUM(Start) As SumOfElapsed
FROM myTable
WHERE Not ( Stop IS NULL)
GROUP BY id



The WHERE clause removes records with incomplete (utilization)
information.


Hoping it may help
Vanderghast, Access MVP


I have a table that has 5 fields:
ID, AutoNumber
Ticket, Number
Techs, Number
Start, Date/Time
Stop, Date/Time

I built 3 seperate queries that output the below information

qryJob:
ID Ticket# Techs Start Stop TotalMH
1 A123 1 8/12/05 9:00 8/12/05 11:00 2.00
2 A123 2 8/12/05 9:00 8/12/05 12:00 6.00
3 A123 1 8/12/05 14:00 8/12/05 18:00 2.00
4 A123 1 8/13/05 9:00 8/13/05 11:00 2.00

I built another query that calculates the Total Man Hours for each
ticket

qryJobMH:
Ticket# TotalMH
A123 14.00

I also have yet another query that calculates the total elapsed time

qryJobElpsd:
Ticket# TotalElpsd
A123 26.00

I REALLY REALLY NEED HELP WITH a query that will output the below
information
Ticket# CrazyTotal
A123 9.00

This is essentially total elapsed time this ticket was being worked
on.
Earliest start time on 8/12 is 9:00 and then the latest end time for
that
bit
of overlap is 12:00 which is 3 hours. Then we have a gap of 2 hours
and
work
again from 14:00 to 18:00 which is an additional 4. The next day we
work
from
9:00 to 11:00 which is another 2. Add them up and we get 9.00 hours.

Any takers?
TIA!!!!

John G.

 
D

Douglas J. Steele

4 separate queries.

Michel's assumed that the first query will be saved as query1, because the
second query refers to query1. Similary, the second query needs to be saved
as query2, since queries 3 and 4 refer to query2.

Nothing wrong with you replacing query1 and query2 with other names, as long
as you change all references.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



John G said:
Thanks for the quick reply and I apologize for my slow response. Sorry if
I
appear ignorant but is what you have listed below 4 different queries that
need to be created seperately or just 1 large query? I guess I'm just not
sure how to put it together in access.
Thank you,
John G.

Michel Walsh said:
Hi,


ah ah... Untested. The easiest solution I think that can solve that
problem,
in general, requires temporary queries. The first one:


SELECT TicketID, Start As Timing, +1 As offset FROM myTable
UNION ALL
SELECT TicketID, Stop, -1 FROM myTable


Observe then that the Start time it to be kept if the running sum of the
offset (against the increasing value of Timing) is +1, and the Stop time
is
to be kept if that same running sum correspond to a running sum of 0.


Get that running sum (query2):

SELECT a.TicketID, a.Timing, SUM(b.offset) As Running
FROM query1 As a INNER JOIN query1 As b
ON a.ticketID = b.ticketID AND b.Timing >= a.Timing
GROUP BY a.TickerID, a.Timing



So, we only have to pick the required values:


SELECT c.TicketID, c.start
FROM myTable As c INNER JOIN query2 as d
ON c.ticketID= d.ticketid AND c.start = d.timing
WHERE d.running = 1
ORDER BY c.TicketID, c.start


for the starting values, and



SELECT c.TicketID, c.stop
FROM myTable As c INNER JOIN query2 as d
ON c.ticketID= d.ticketid AND c.stop = d.timing
WHERE d.running = 0
ORDER BY c.TicketID, c.stop

supplies the stopping values, for the merged (or not merge) intervals.





Hoping it may help,
Vanderghast, Access MVP


John G said:
Hi Michel, I apologize if I seem slow but I think my wires got crossed
somewhere and I explained what I was looking for poorly. What I am
after
is a
query that will take the date/times from the table below and treat the
overlapping date/times as one record with the earliest date/time and
the
lastest date/time of the overlapping records combimed into one.

So the table looks exactly like this:
ID Ticket# Techs Start Stop
1 123 1 08/12/2005 8:00 08/12/2005 11:00
2 123 2 08/12/2005 9:00 08/12/2005 12:00
3 123 1 08/12/2005 14:00 08/12/2005 18:00
4 123 1 08/13/2005 9:00 08/13/2005 11:00

the query I'm looking for needs to return this:
Ticket# Start Stop Total
123 08/12/2005 8:00 08/12/2005 12:00 4.00 <---combination of
overlapping
times ID 1 and 2
123 08/12/2005 14:00 08/12/2005 18:00 2.00
123 08/13/2005 9:00 08/13/2005 11:00 2.00

The total field I got using this expression which works just fine:
Total: Format(((DateDiff("n",[Start],[Stop])/60)),"Fixed")

I just can't for the life of me figure out how to combine the
overlapping
times.

Any ideas?

:

Hi,


You are not supposed to format the data, BEFORE making the
computation,
no.

The solution was based on the fact that:

L1-a1 + L2-a2 + L3-a3 + ..... + L9-a9


(ie, leaving minus arriving ) is the same as


( L1 + L2 + L3 + .... + L9 ) - ( a1 + a2 + a3 + ... + a9 )

which is the same as


SUM(L) - SUM(a)


When you say it return 27 (hours) and return 21, are you sure it
really
SHOULD return 27.


Now, if your data exceed 24 hour, you may get a result as 31st
December
1899 01:00:00 instead of 25:00:00, as example. That, you have to
format
to get 25:00:00 rather than this date.

Int( 1E-5 + 24 * x ) & Format( x, ":nn:ss")


for x a positive period of time interval should do the job.



Hoping it may help,
Vanderghast, Access MVP



Thanks Michel,

Thank you for the quick reply. I am storing the dates with the
times.
The example data was part of a query with an added calculated field
to
give
the TotalMH. TotalMH is
Format(((DateDiff("n",[Start],[Stop])/60)*[Techs]),"Fixed"). This is
without
grouping.
Then in qryJobMH I grouped by Ticket# and then used
Sum(IIf(qryJob!TotalMH<>"",qryJob!TotalMH,"0.00")) AS TotalMH (*I
should
probably use a different name like TotalJobMH) for that query.

I'm pretty new at this and am not really sure if the query you
provided
will
be able to do what I need it to. For instance when I ran it and say
increased
ID 2 to have 9 Techs the total should be 27 and the query returned
only
21:00. Do I need to convert the returned data before I format it for
display?

Thanks for the help!

:

Hi,



Always store the date with the time, and then it seems to be a
matter
to
subtract SUMs:

SELECT id, SUM(Stop)-SUM(Start) As SumOfElapsed
FROM myTable
WHERE Not ( Stop IS NULL)
GROUP BY id



The WHERE clause removes records with incomplete (utilization)
information.


Hoping it may help
Vanderghast, Access MVP


I have a table that has 5 fields:
ID, AutoNumber
Ticket, Number
Techs, Number
Start, Date/Time
Stop, Date/Time

I built 3 seperate queries that output the below information

qryJob:
ID Ticket# Techs Start Stop TotalMH
1 A123 1 8/12/05 9:00 8/12/05 11:00 2.00
2 A123 2 8/12/05 9:00 8/12/05 12:00 6.00
3 A123 1 8/12/05 14:00 8/12/05 18:00 2.00
4 A123 1 8/13/05 9:00 8/13/05 11:00 2.00

I built another query that calculates the Total Man Hours for
each
ticket

qryJobMH:
Ticket# TotalMH
A123 14.00

I also have yet another query that calculates the total elapsed
time

qryJobElpsd:
Ticket# TotalElpsd
A123 26.00

I REALLY REALLY NEED HELP WITH a query that will output the below
information
Ticket# CrazyTotal
A123 9.00

This is essentially total elapsed time this ticket was being
worked
on.
Earliest start time on 8/12 is 9:00 and then the latest end time
for
that
bit
of overlap is 12:00 which is 3 hours. Then we have a gap of 2
hours
and
work
again from 14:00 to 18:00 which is an additional 4. The next day
we
work
from
9:00 to 11:00 which is another 2. Add them up and we get 9.00
hours.

Any takers?
TIA!!!!

John G.

 
J

John G

Thanks Douglas, I've named each query in order query1, query2, query3 and
query4.
Now this is just an assumption on my part but would I now create a 5th query
that joins queryies 3 and 4 on ticketID? I guess I can't figure out how to
put these to use and get them to output what I had listed below. When I run
queries 3 and 4 seperately on the sample data I have listed below no records
are being returned.
Thanks,
John G

Douglas J. Steele said:
4 separate queries.

Michel's assumed that the first query will be saved as query1, because the
second query refers to query1. Similary, the second query needs to be saved
as query2, since queries 3 and 4 refer to query2.

Nothing wrong with you replacing query1 and query2 with other names, as long
as you change all references.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)



John G said:
Thanks for the quick reply and I apologize for my slow response. Sorry if
I
appear ignorant but is what you have listed below 4 different queries that
need to be created seperately or just 1 large query? I guess I'm just not
sure how to put it together in access.
Thank you,
John G.

Michel Walsh said:
Hi,


ah ah... Untested. The easiest solution I think that can solve that
problem,
in general, requires temporary queries. The first one:


SELECT TicketID, Start As Timing, +1 As offset FROM myTable
UNION ALL
SELECT TicketID, Stop, -1 FROM myTable


Observe then that the Start time it to be kept if the running sum of the
offset (against the increasing value of Timing) is +1, and the Stop time
is
to be kept if that same running sum correspond to a running sum of 0.


Get that running sum (query2):

SELECT a.TicketID, a.Timing, SUM(b.offset) As Running
FROM query1 As a INNER JOIN query1 As b
ON a.ticketID = b.ticketID AND b.Timing >= a.Timing
GROUP BY a.TickerID, a.Timing



So, we only have to pick the required values:


SELECT c.TicketID, c.start
FROM myTable As c INNER JOIN query2 as d
ON c.ticketID= d.ticketid AND c.start = d.timing
WHERE d.running = 1
ORDER BY c.TicketID, c.start


for the starting values, and



SELECT c.TicketID, c.stop
FROM myTable As c INNER JOIN query2 as d
ON c.ticketID= d.ticketid AND c.stop = d.timing
WHERE d.running = 0
ORDER BY c.TicketID, c.stop

supplies the stopping values, for the merged (or not merge) intervals.





Hoping it may help,
Vanderghast, Access MVP


Hi Michel, I apologize if I seem slow but I think my wires got crossed
somewhere and I explained what I was looking for poorly. What I am
after
is a
query that will take the date/times from the table below and treat the
overlapping date/times as one record with the earliest date/time and
the
lastest date/time of the overlapping records combimed into one.

So the table looks exactly like this:
ID Ticket# Techs Start Stop
1 123 1 08/12/2005 8:00 08/12/2005 11:00
2 123 2 08/12/2005 9:00 08/12/2005 12:00
3 123 1 08/12/2005 14:00 08/12/2005 18:00
4 123 1 08/13/2005 9:00 08/13/2005 11:00

the query I'm looking for needs to return this:
Ticket# Start Stop Total
123 08/12/2005 8:00 08/12/2005 12:00 4.00 <---combination of
overlapping
times ID 1 and 2
123 08/12/2005 14:00 08/12/2005 18:00 2.00
123 08/13/2005 9:00 08/13/2005 11:00 2.00

The total field I got using this expression which works just fine:
Total: Format(((DateDiff("n",[Start],[Stop])/60)),"Fixed")

I just can't for the life of me figure out how to combine the
overlapping
times.

Any ideas?

:

Hi,


You are not supposed to format the data, BEFORE making the
computation,
no.

The solution was based on the fact that:

L1-a1 + L2-a2 + L3-a3 + ..... + L9-a9


(ie, leaving minus arriving ) is the same as


( L1 + L2 + L3 + .... + L9 ) - ( a1 + a2 + a3 + ... + a9 )

which is the same as


SUM(L) - SUM(a)


When you say it return 27 (hours) and return 21, are you sure it
really
SHOULD return 27.


Now, if your data exceed 24 hour, you may get a result as 31st
December
1899 01:00:00 instead of 25:00:00, as example. That, you have to
format
to get 25:00:00 rather than this date.

Int( 1E-5 + 24 * x ) & Format( x, ":nn:ss")


for x a positive period of time interval should do the job.



Hoping it may help,
Vanderghast, Access MVP



Thanks Michel,

Thank you for the quick reply. I am storing the dates with the
times.
The example data was part of a query with an added calculated field
to
give
the TotalMH. TotalMH is
Format(((DateDiff("n",[Start],[Stop])/60)*[Techs]),"Fixed"). This is
without
grouping.
Then in qryJobMH I grouped by Ticket# and then used
Sum(IIf(qryJob!TotalMH<>"",qryJob!TotalMH,"0.00")) AS TotalMH (*I
should
probably use a different name like TotalJobMH) for that query.

I'm pretty new at this and am not really sure if the query you
provided
will
be able to do what I need it to. For instance when I ran it and say
increased
ID 2 to have 9 Techs the total should be 27 and the query returned
only
21:00. Do I need to convert the returned data before I format it for
display?

Thanks for the help!

:

Hi,



Always store the date with the time, and then it seems to be a
matter
to
subtract SUMs:

SELECT id, SUM(Stop)-SUM(Start) As SumOfElapsed
FROM myTable
WHERE Not ( Stop IS NULL)
GROUP BY id



The WHERE clause removes records with incomplete (utilization)
information.


Hoping it may help
Vanderghast, Access MVP


I have a table that has 5 fields:
ID, AutoNumber
Ticket, Number
Techs, Number
Start, Date/Time
Stop, Date/Time

I built 3 seperate queries that output the below information

qryJob:
ID Ticket# Techs Start Stop TotalMH
1 A123 1 8/12/05 9:00 8/12/05 11:00 2.00
2 A123 2 8/12/05 9:00 8/12/05 12:00 6.00
3 A123 1 8/12/05 14:00 8/12/05 18:00 2.00
4 A123 1 8/13/05 9:00 8/13/05 11:00 2.00

I built another query that calculates the Total Man Hours for
each
ticket

qryJobMH:
Ticket# TotalMH
A123 14.00

I also have yet another query that calculates the total elapsed
time

qryJobElpsd:
Ticket# TotalElpsd
A123 26.00

I REALLY REALLY NEED HELP WITH a query that will output the below
information
Ticket# CrazyTotal
A123 9.00

This is essentially total elapsed time this ticket was being
worked
on.
Earliest start time on 8/12 is 9:00 and then the latest end time
for
that
bit
of overlap is 12:00 which is 3 hours. Then we have a gap of 2
hours
and
work
again from 14:00 to 18:00 which is an additional 4. The next day
we
work
from
9:00 to 11:00 which is another 2. Add them up and we get 9.00
hours.

Any takers?
TIA!!!!

John G.

 
M

Michel Walsh

Hi,



With

Table1
TicketID Start Stop
123 8/12/2005 08:00:00 8/12/2005 11:00:00
123 8/12/2005 09:00:00 8/12/2005 12:00:00
123 8/12/2005 14:00:00 8/12/2005 18:00:00
123 8/13/2005 09:00:00 8/13/2005 11:00:00



The first query

SELECT TicketID, Start As Timing, +1 As offset FROM table1
UNION ALL
SELECT TicketID, Stop, -1 FROM table1

returns


Query1
TicketID Timing offset
123 8/12/2005 08:00:00 1
123 8/12/2005 09:00:00 1
123 8/12/2005 14:00:00 1
123 8/13/2005 09:00:00 1
123 8/12/2005 11:00:00 -1
123 8/12/2005 12:00:00 -1
123 8/12/2005 18:00:00 -1
123 8/13/2005 11:00:00 -1



The second query ( two typos in the original text, well one typo and one
inversion):

SELECT a.TicketID, a.Timing, SUM(b.offset) As Running
FROM query1 As a INNER JOIN query1 As b
ON a.ticketID = b.ticketID AND b.Timing <= a.Timing
GROUP BY a.TicketID, a.Timing


returns

Query2
TicketID Timing Running
123 8/12/2005 08:00:00 1
123 8/12/2005 09:00:00 2
123 8/12/2005 11:00:00 1
123 8/12/2005 12:00:00 0
123 8/12/2005 14:00:00 1
123 8/12/2005 18:00:00 0
123 8/13/2005 09:00:00 1
123 8/13/2005 11:00:00 0



the third and fourth queries,

SELECT c.TicketID, c.start
FROM table1 As c INNER JOIN query2 as d
ON c.ticketID= d.ticketid AND c.start = d.timing
WHERE d.running = 1
ORDER BY c.TicketID, c.start


as example, returns

Query3
TicketID start
123 8/12/2005 08:00:00
123 8/12/2005 14:00:00
123 8/13/2005 09:00:00



and


SELECT c.TicketID, c.stop
FROM table1 As c INNER JOIN query2 as d
ON c.ticketID= d.ticketid AND c.stop = d.timing
WHERE d.running = 0
ORDER BY c.TicketID, c.stop


to get

Query4
TicketID stop
123 8/12/2005 12:00:00
123 8/12/2005 18:00:00
123 8/13/2005 11:00:00





To "easily" glue back the last two queries, horizontally, we can use 3 more
queries... yea!


Query5:

SELECT a.TicketID, a.start, COUNT(*) As rank
FROM query3 As a INNER JOIN query3 As b
ON a.ticketID=b.ticketID and a.start >= b.start
GROUP BY a.ticketID, a.start


Query6:

SELECT a.TicketID, a.stop, COUNT(*) As rank
FROM query4 As a INNER JOIN query4 As b
ON a.ticketID=b.ticketID and a.stop >= b.stop
GROUP BY a.ticketID, a.stop



and our last query, the only one we will have to call, in fact, to make all
the sequence running, transparently:


Query7:

SELECT Query5.TicketID, Query5.start, Query6.stop
FROM Query5 INNER JOIN Query6
ON (Query5.TicketID = Query6.TicketID)
AND (Query5.rank = Query6.rank)



Query7
TicketID start stop
123 8/12/2005 08:00:00 8/12/2005 12:00:00
123 8/12/2005 14:00:00 8/12/2005 18:00:00
123 8/13/2005 09:00:00 8/13/2005 11:00:00





Hoping it may help
Vanderghast, Access MVP
 
J

John G

Thank you so much for putting that together! You have no idea how awsome you
are! I threw everything I had at it and it works great even when overlapping
accross days! You are my hero!!!
 
J

John G

I have one last question and then I swear I'll leave you alone...Every time I
run query7 mt MDB file grows a little bigger. I went and ran it 10 times in a
row and my file went from 5 MB to 8 MB. If I go and compact the databse it
shrinks it back down but I was wondering if there was a way to prevent this
from happening in the first place?
Thanks again,
John G.
 
M

Michel Walsh

Hi,



nope, that is "normal", the "dirty" space (previously occupied by the
intermediate data) is only claim back when space is needed, or when the
database is compacted. You should not be concerned with that, unless you
have to send the file .... in that case compact the file before "zipping"
it. Otherwise, normal operation, not just that sequence of queries, is quite
likely to make your file size increase: speed is considered somehow more
relevant, by default, than space, as long as there is space, that is.



Hoping it may help,
Vanderghast, Access MVP
 
J

John G

Thanks for the info!

Michel Walsh said:
Hi,



nope, that is "normal", the "dirty" space (previously occupied by the
intermediate data) is only claim back when space is needed, or when the
database is compacted. You should not be concerned with that, unless you
have to send the file .... in that case compact the file before "zipping"
it. Otherwise, normal operation, not just that sequence of queries, is quite
likely to make your file size increase: speed is considered somehow more
relevant, by default, than space, as long as there is space, that is.



Hoping it may help,
Vanderghast, Access MVP
 
J

John G

err....I'm really sorry to bother you once again but I found something that
seems to muck things up a bit. If there are 2 records for the same TicketID
that have the same start and end times it appears to throw the whole works
off.

I changed the first two records so that the start and end times match and
now query7 isn't returning any data at all.

Any ideas?
As always, I thank you!

John G
 
M

Michel Walsh

Hi,


Indeed, I assumed Start and Stop time where all different. If that
assumption does not hold, the queries won't work.

I have to think about a solution when Start and Stop times can occur
multiple time.


Vanderghast, Access MVP
 
M

Michel Walsh

Hi,


Here something that seems to work:

AllStarts
--------------
SELECT DISTINCT TicketID, Start
FROM Table1;


AllStops
------------
SELECT DISTINCT TicketID, Stop
FROM table1;


KeepStarts
------------------
SELECT a.TicketID, a.Start
FROM AllStarts As a LEFT JOIN Table1 As b
ON a.TicketID = b.TicketID AND a.start > b.start AND a.start <= b.stop
GROUP BY a.TicketID, a.Start
HAVING COUNT(*)=1



KeepStops
----------------
SELECT a.TicketID, a.Stop
FROM AllStops As a LEFT JOIN Table1 As b
ON a.TicketID = b.TicketID AND a.stop < b.stop AND a.stop >= b.start
GROUP BY a.TicketID, a.Stop
HAVING COUNT(*)=1



It is then a matter to merge together KeepStarts and KeepStops, a little bit
as we did before with query3 and query4.


I tried with the following set of data:

Table1
TicketID Start Stop
123 8/12/2005 08:00:00 8/12/2005 11:00:00
123 8/12/2005 09:00:00 8/12/2005 12:00:00
123 8/12/2005 14:00:00 8/12/2005 18:00:00
123 8/13/2005 09:00:00 8/13/2005 11:00:00
123 8/12/2005 08:00:00 8/12/2005 12:00:00



More tests are surely required.


Hoping it may help,
Vanderghast, Access MVP
 
J

John G

Hi again Michel...I don't think I'm doing something correctly here. I tried
to substitute KeepStarts and KeepStops for query3 and 4 and it didn't work
out so well. Also, I can't seem to figure out how to merge the two as you
suggested (my mind is not working well today at all). So, am I essentially
supposed to substitute query3 and 4 for KeepStarts and KeepStops or do I need
to merge KeepStarts and KeepStops and then run it through the 7 queries? If I
need to merge it how do I accomplish that? Thank you!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top