Bloody Microsoft (#328923 in a series)
Tuesday, November 2nd, 2004 12:39 pmI have a set of records*. I am grouping them by PO Number.
edited to correct record counts, which I misremembered...
If I specify Min on the Due Date, I get 1673 records.
If I specify Max on the Due Date, I get 1566 records.
Therefore, I am specifying 'get a low-IQ second jobber and have it generate this report manually'.
*doomed records, as they live in an Access 97 database. Pray for them.
edited to correct record counts, which I misremembered...
If I specify Min on the Due Date, I get 1673 records.
If I specify Max on the Due Date, I get 1566 records.
Therefore, I am specifying 'get a low-IQ second jobber and have it generate this report manually'.
*doomed records, as they live in an Access 97 database. Pray for them.
no subject
Date: Tuesday, November 2nd, 2004 04:59 am (UTC)no subject
Date: Tuesday, November 2nd, 2004 05:14 am (UTC)Anyway, why would there be a Max and not a Min?
no subject
Date: Tuesday, November 2nd, 2004 05:22 am (UTC)no subject
Date: Tuesday, November 2nd, 2004 05:28 am (UTC)I got the numbers the wrong way round, though:
SELECT tblPOHistory.Cat, tblPOHistory.PONO, Max(tblPOHistory.CreateDate) AS CreateDate
FROM tblPOHistory
GROUP BY tblPOHistory.Cat, tblPOHistory.PONO
HAVING (((Max(tblPOHistory.CreateDate))<[start date]));
gives 1566 recs
SELECT tblPOHistory.Cat, tblPOHistory.PONO, Min(tblPOHistory.CreateDate) AS CreateDate
FROM tblPOHistory
GROUP BY tblPOHistory.Cat, tblPOHistory.PONO
HAVING (((Min(tblPOHistory.CreateDate))<[start date]));
gives 1673 recs.
Yes, I am using the same start date, in case you wondered!
no subject
Date: Tuesday, November 2nd, 2004 05:34 am (UTC)no subject
Date: Tuesday, November 2nd, 2004 05:46 am (UTC)Assuming that there is a spread of CreateDate values for any given Cat/PONO combination, then the set of MAX(CreateDate) values potentially differs from the set of MIN(CreateDate) values, thus potentially different numbers of records will meet the conditions in the HAVING clause. I think.
no subject
Date: Tuesday, November 2nd, 2004 05:55 am (UTC)However, if you are saying that there is only ONE row per Cat/PONO combination, and no NULLs for CreateDate, then I agree that there should be no difference between MIN and MAX in that context (and, really, no reason to be using MIN and MAX unless to demonstrate how crap Microsoft can be :-).
no subject
Date: Tuesday, November 2nd, 2004 06:01 am (UTC)For each cat/po combination there should be a Max Date and a Min Date -- even if they are the same date, because derived from the same record.
Here is the first record in the 'Min' set, sorted by PO Number:
Cat PONO CreateDate
ES 1110691 29/10/2004
So, the PO Number on the first record in the 'Max' set, sorted by PO number, should be ... which of the following?
a) 1110691
b) something else
no subject
Date: Tuesday, November 2nd, 2004 06:03 am (UTC)Cat PONO CreateDate
ES 1111891 29/10/2004
Poor ol' 1110691 ain't there no more.
And on that note I must away ...
no subject
Date: Tuesday, November 2nd, 2004 06:24 am (UTC)no subject
Date: Tuesday, November 2nd, 2004 10:09 am (UTC)Ah well. Stuff Access. Off to use non-Microsoft software for novelly thing.
no subject
Date: Tuesday, November 2nd, 2004 04:51 pm (UTC)I can't see why the specific data you mention is producing odd results. Where is [start date] coming from? Could there be a time part to CreateDate that's throwing things off?
no subject
Date: Wednesday, November 3rd, 2004 01:52 am (UTC)I think the issue is being blurred by the existence of a definite problem in the results.
I think Access has some little-known features like this ...
no subject
Date: Wednesday, November 3rd, 2004 03:51 am (UTC)Try this:
SELECT tblPOHistory.Cat, tblPOHistory.PONO, Max(tblPOHistory.CreateDate) AS CreateDate
FROM tblPOHistory
WHERE (((tblPOHistory.CreateDate)<[start date]))
GROUP BY tblPOHistory.Cat, tblPOHistory.PONO
The difference is that the WHERE clause is applied before the GROUP BY. So if a condition is in the WHERE, it will select only records that meet that condition, then group those, but if it's in the HAVING, it will select only groups that meet the condition. This is why you had to apply an aggragate function to CreateDate (which I removed).
no subject
Date: Wednesday, November 3rd, 2004 04:03 am (UTC)Yes, I hadn't intended the Min/Max to apply to the selection -- I just wanted the Min/Max of what was selected!
no subject
Date: Tuesday, November 2nd, 2004 05:39 am (UTC)