I have database that runs a query across several tables. That query's results are then sorted by department, office, employee, date, receipt order. The problem is - there is no unique or primary key anywhere in this data. The departments are numbered 1-25, each department has an office numbered 1-12, each office has up to 10 employees (numbered 1-10), and of course, there are entries every day of the year, and for each employee's sales on a given date, their receipts are numbered 1-whatever. Each receipt has a type code on it, for the type of product or service offered. A sample might look like this:
DEPT Office Employee Date Reciept Code
1 2 1 6/5/06 56 102
1 1 1 6/5/06 108 102
4 1 1 6/5/06 109 108
4 1 1 6/5/06 110 200
What I want to be able to do is run a new query on these results. Going through each record in the list and selecting that record as a result in my new query IF the code for this particular record is 108 AND the code for the VERY NEXT record in the query is 200. So, with the above data, it would return record #3.
Any ideas how I can achieve this as simply as possible?
DEPT Office Employee Date Reciept Code
1 2 1 6/5/06 56 102
1 1 1 6/5/06 108 102
4 1 1 6/5/06 109 108
4 1 1 6/5/06 110 200
What I want to be able to do is run a new query on these results. Going through each record in the list and selecting that record as a result in my new query IF the code for this particular record is 108 AND the code for the VERY NEXT record in the query is 200. So, with the above data, it would return record #3.
Any ideas how I can achieve this as simply as possible?