ChrisCalvert
Technical User
I have two tables.
Account with the (relevant) fields
ACNTNO - Primary Key, the account number
OPNDT - Date/Time, Date account opened
EFFDT -Date/Time, (will explain)
and
Sales
ACTNO- account number
RPTDT - Date/Time, Timestamp for this Volume (I.e. 6/1/04 is June'04 sales for this account)
Now the part that is causing me grief. I need to figure the best way to create code or queries to update EFFDT like this:
The EFFDT is the 'effective date of open'. This is created when, in the first two months - if there was consecutively a volume of less than 10- the open date is effectively moved up one month. HOWEVER, if the third month has no sales the EFFDT reverts back to the original OPNDT. Example: Opened in 6/04, no 6/4 Volume: EFFDT = 7/4, No 7/4 Volume: EFFDT=7/4. BUT this only happens as long as the <10 volumes are consecutive. If there is volume in the 1st month, but not the 2nd or 3rd (or whatever) then the EFFDT will never move from the OPNDT. If there is <10 volume in month one, but month two has >10 volume, then EFFDT gets pushed up for the 1st month, but never again. .....WHEW.
So my first solution was just to loop through the 'Sales' as an ADO recordset, and with a loop inside that find and appropriately update the corresponding 'Account' record. But this is taking a very long time.
A second Idea I have is to loop through the 'Account' table, and then use SQL to open a recordset of the matching 'Sales' and update as needed. I don't know if this would be any faster, as I don't know the (time) consequences of opening up a new recordset for every entry in 'Account'. This is a proceedure that would be run monthly (after new sales records are in and before a report that uses EFFDT is run). Anyway, I know this is pretty complicated, and I am not sure I explained it that well. Any high level suggestions on what is a good way to approach this would be much appreciated.
Account with the (relevant) fields
ACNTNO - Primary Key, the account number
OPNDT - Date/Time, Date account opened
EFFDT -Date/Time, (will explain)
and
Sales
ACTNO- account number
RPTDT - Date/Time, Timestamp for this Volume (I.e. 6/1/04 is June'04 sales for this account)
Now the part that is causing me grief. I need to figure the best way to create code or queries to update EFFDT like this:
The EFFDT is the 'effective date of open'. This is created when, in the first two months - if there was consecutively a volume of less than 10- the open date is effectively moved up one month. HOWEVER, if the third month has no sales the EFFDT reverts back to the original OPNDT. Example: Opened in 6/04, no 6/4 Volume: EFFDT = 7/4, No 7/4 Volume: EFFDT=7/4. BUT this only happens as long as the <10 volumes are consecutive. If there is volume in the 1st month, but not the 2nd or 3rd (or whatever) then the EFFDT will never move from the OPNDT. If there is <10 volume in month one, but month two has >10 volume, then EFFDT gets pushed up for the 1st month, but never again. .....WHEW.
So my first solution was just to loop through the 'Sales' as an ADO recordset, and with a loop inside that find and appropriately update the corresponding 'Account' record. But this is taking a very long time.
A second Idea I have is to loop through the 'Account' table, and then use SQL to open a recordset of the matching 'Sales' and update as needed. I don't know if this would be any faster, as I don't know the (time) consequences of opening up a new recordset for every entry in 'Account'. This is a proceedure that would be run monthly (after new sales records are in and before a report that uses EFFDT is run). Anyway, I know this is pretty complicated, and I am not sure I explained it that well. Any high level suggestions on what is a good way to approach this would be much appreciated.