You can do it by creating another query which joins one of the queries below
to itself, so if the query has been saved as qryLastTwoVisits the final query
would be like this:
SELECT Q1.Store,
Q2.VisitDate As Visit1,
Q2.Score As Score1,
IIF(Q1.VisitDate =
Q2.VisitDate ,
NULL,Q1.VisitDate)
AS Visit2,
IIF(Q1.VisitDate =
Q2.VisitDate ,
NULL,Q1.Score)
AS Score2
FROM qryLastTwoVisits AS Q1,
qryLastTwoVisits AS Q2
WHERE Q1.Store = Q2.Store
AND (Q1.VisitDate > Q2.VisitDate
OR (SELECT COUNT(*)
FROM qryLastTwoVisits As Q3
WHERE Q3.Store = Q1.Store) = 1);
Note that in this case the join is done in the WHERE clause on the Stores
being the same, and the either one visit date being later that the other or
there having been only one visit to the store in question.
The IIF function calls and the subquery in the WHERE clause are to take
account of a store only having had one visit, in which case the Visit2 and
Score2 columns will contain Nulls. Otherwise without the IIF function call
the dates and scores would be repeated in the pairs of columns, and without
the subquery those rows would not be returned at all.
Ken Sheridan
Stafford, England