Lee said:
With the help of Mr. Foster I have created a expression as follows.
SELECT A.FlightDate
FROM [Year2005 Pilot Info] AS A
GROUP BY A.FlightDate
HAVING ((((SELECT Sum([Cy2k2ReportT501Hrs]) FROM [Year2005 Pilot Info]
WHERE FlightDate <= A.FlightDate) Mod 25)=0))
ORDER BY A.FlightDate DESC;
What I am trying to achieve is to add the hours in "Cy2k2ReportT501Hrs"
field until I reach 25 hours and give me cooresponding date located in the
"FlightDate" field. The result it is giving me is a date but it is not 25
hours, it is less.
Hi Lee,
First (meaning no offense), but MG is one of the
premier contributors on this newsgroup, and my
guess is that if you had continued this discussion
in the previous thread, Mr. Foster would have
likely *immediately* responded with more assistance.
The only thing I can think of is that you may want
your group to include a PilotID (or PilotName)...
something like?
SELECT A.FlightDate, A.PilotName
FROM [Year2005 Pilot Info] AS A
GROUP BY A.FlightDate, A.PilotName
HAVING
((((SELECT Sum(t.[Cy2k2ReportT501Hrs])
FROM [Year2005 Pilot Info] As t
WHERE
t.FlightDate <= A.FlightDate
AND
t.PilotName = A.PilotName)
Mod 25)=0))
ORDER BY A.FlightDate DESC;
If your [Year2005 PilotInfo] table (query?)
contained more than one pilot, then your
query above would probably hit 25 hours
total on a date when a *pilot* did not have
a full 25 hours.
Does that make sense in your situation?
Another thought was how are you storing
the hours? I made a small test table called
"tblLee" to test various number types.
FlightDate FloatHours LongHours CurHours
5/1/2005 4.5 5 4.5
5/2/2005 5.1 5 5.1
5/3/2005 4.2 4 4.2
5/4/2005 6.2 6 6.2
5/5/2005 2 2 2
5/6/2005 3 3 3
5/7/2005 1.1 1 1.1
and ran following query
SELECT A.FlightDate
FROM tblLee AS A
GROUP BY A.FlightDate
HAVING ((((SELECT Sum(t.[FloatHours]) FROM tblLee As t
WHERE t.FlightDate <= A.FlightDate) Mod 25)=0))
ORDER BY A.FlightDate DESC;
and got what one would expect.
FlightDate
5/6/2005
It may be that I just got lucky on summing the
limited float hours. Arithmetic on floats can be
a big gotcha. I usually create a wrapper function
around CDec() so I can use this function in
a query (maybe that has changed in later versions
of Access) to change the floats to Decimal and
expect any arithmetic to work.
I also ran this check query (you don't say
what type of field the Hours are stored in):
SELECT
t.FlightDate,
t.FloatHours,
(SELECT Sum(t1.FloatHours) FROM tblLee As t1 WHERE
t1.FlightDate<=t.FlightDate) AS SumPrevFloat,
(SELECT Sum(t1.FloatHours) FROM tblLee As t1 WHERE
t1.FlightDate<=t.FlightDate) Mod 25 AS MOD25Float,
t.LongHours,
(SELECT Sum(t2.LongHours) FROM tblLee As t2 WHERE
t2.FlightDate<=t.FlightDate) AS SumPrevLong,
(SELECT Sum(t2.LongHours) FROM tblLee As t2 WHERE
t2.FlightDate<=t.FlightDate) Mod 25 AS MOD25Long,
t.CurHours,
(SELECT Sum(t3.CurHours) FROM tblLee As t3 WHERE
t3.FlightDate<=t.FlightDate) AS SumPrevCur,
(SELECT Sum(t3.CurHours) FROM tblLee As t3 WHERE
t3.FlightDate<=t.FlightDate) Mod 25 AS MOD25Cur
FROM tblLee AS t;
and got
FlightDate FloatHours SumPrevFloat MOD25Float LongHours SumPrevLong
MOD25Long CurHours SumPrevCur MOD25Cur
5/1/2005 4.5 4.5 4 5 5 5 4.5 $4.50 4
5/2/2005 5.1 9.6 10 5 10 10 5.1 $9.60 10
5/3/2005 4.2 13.8 14 4 14 14 4.2 $13.80 14
5/4/2005 6.2 20 20 6 20 20 6.2 $20.00 20
5/5/2005 2 22 22 2 22 22 2 $22.00 22
5/6/2005 3 25 0 3 25 0 3 $25.00 0
5/7/2005 1.1 26.1 1 1 26 1 1.1 $26.10 1
All seemed well.
Is there any difference in what you are
working with, versus the simple example
above, i.e., are "FlightDate" values actually
type Date versus formatted strings, etc.?
good luck,
gary