|
-
Jul 15th, 2008, 07:29 PM
#1
Thread Starter
PowerPoster
HELP -- Logic Issue
Primary Key Indexed
AutoNumber fldDate fldFlag fldAmount
Records are entered into the Database based on Date/Time (FIFO) order.
I need to match records daily based on fldFlag which will be either A or B.
If there are an equal number of A's and B's they need to be matched (entered into Excel on the same row) in FIFO order even though the query results may not appear in FIFO order.
For example:
Date A
Date A
Date B
Date A
Date B
Date B
If there are not an equal number of A's and B's. Then the number of A's or B's to be carried over to the next day needs to be calculated. If A's, the lowest amounts will carryover, if B's the highest amounts will carryover.
I have things working if there are an equal number of A's and B's.
Currently I Query the DB by Date and extract Todays Records
I then loop through the Query Results and Count the A's and B's
If Equal, I load two array structures in date order -- one containing A's
the other B's
I then insert each A and B data on a row into Excel.
======== PROBLEM ================
The Carryover has me puzzled so far.
One thought was based on my counts,
If I have more A's than B's I could Query fldAmounts of just A's and Sort in ASC order. If B's I would sort in DESC order.
Then based on the count I could get the number of "top" records which will carry over and store them either in an array or a separate DB table and then load the subsequent records which would now be equal into the structures for updating Excel rows.
>> But what is the best way to incorporate the records that were "HELD" (CarryOver) into the query for the next day --- UNION Query?????
OR
Better suggestion PLEASE
Last edited by dw85745; Jul 15th, 2008 at 07:40 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|