| re: combining duplicate data onto a single record
There may people out there who are smarter than I am and who have a
better answer, but here is one for you.
You only showed a max of 2 page numbers, but I am guessing that you may
have more. If you only have two, this could be done this way.
SELECT aPage1.partnumber,MaxPrice,pagenumber1,pagenumber2
FROM
(SELECT partnumber, Max(price) AS MaxPrice, Min(pagenumber) AS
pagenumber1
FROM Table1
GROUP BY partnumber) as aPage1 LEFT JOIN
(SELECT partnumber, Max(pagenumber) AS pagenumber2 FROM Table1
GROUP BY partnumber
HAVING count(pagenumber)>1) as aPage2 ON
aPage1.partnumber=aPage2.partnumber
If you need it to be dynamic (so that you can have x number of pages),
you'll need to buld a table so that access can build it's execution
plan for the crosstab. These are pretty easy and can be done without
the user ever knowing - using vb.
First Build a table:
SELECT Table1.partnumber, Table1.price, Table1.pagenumber, "PageNumber"
& (select count(pagenumber) from table1 as t WHERE
t.partnumber=table1.partnumber AND t.pagenumber<=table1.pagenumber) AS
PageCount INTO PageCount
FROM Table1;
Then run your crosstab query on the built table:
TRANSFORM Max(PageCount.pagenumber) AS MaxOfpagenumber
SELECT PageCount.partnumber, Max(PageCount.price) AS MaxPrice
FROM PageCount
GROUP BY PageCount.partnumber
PIVOT PageCount.PageCount;
Hope that's not too confusing
Pachydermitis |