J
Jack Sheet
Hi all
I am a real newbie to Access (I don't even know how to insert a calculated
date into a record during an action query) and John Spencer gave me a lot of
help in the gettingstarted newsgroup on a similar problem. Perhaps this
question should be addressed there but I feel it is getting a bit more
complicated, and it is query-specific so I put it here. Apologies if in
error. (John, if you read this you will recognise the previous problem.)
I have a database with 2 tables: T_Clients and T_Tasks.
T_Clients has 3 fields:
ID_Clients = autonumber, primary key
YEM = number, integer, validation permits range >0 and <13 (representing a
month)
YED = number, integer, validation permits range >0 and <32 (representing a
day in a month)
(the user is currently trusted not to enter impossible values within those
ranges, ie 31 June or 30 February)
T_Tasks has 3 fields:
ID_Tasks = autonumber, primary key
ID_Clients = number, long integer
PeriodTo = date
There is a one (T_Clients.ID_Clients) to many (T_Tasks.ID_Clients)
relationship with enforced referencial integrity.
In my sample data, T_Clients has 3 records
ID_Clients YEM YED
20 4 30
21 5 31
22 6 30
T_Tasks has 3 records
ID_Tasks ID_Clients PeriodTo
11 20 2004-04-30
12 21 2005-05-31
13 22 2006-06-30
I am needing an Append query, that creates records in T_Tasks. I don't care
how many intermediate Select Queries I need to create to get to the final
destination.
User inputs a date (call it "RollDate") and for this example say the user
input date 2006-06-30 (I am flexible about where this needs to be stored, or
whether it is input on a prompt when the append query is run).
The query then adds records to T_Tasks, by considering each instance of
ID_Clients in T_Clients and, for each such entry it adds a new period in
T_Tasks if an appropriate period does not already exist in T_Tasks for that
ID_Clients value. An appropriate period is one that ends on the latest date
on or before the RollDate but bearing the month and day-of-the-month
particular to that value of ID_Clients as specified in T_Clients.YEM and
T_Clients.YED.
So, for the sample data given:
It should ignore ID_Clients = 22, because the year end for that client is
set to 30 June, the latest such date on or before rolldate (30 June 2006)
is, coincidentally, 30 June 2006 and there already exists a record with that
date in the PeriodTo field.
It should create one record for ID_Clients = 21, and populate the PeriodTo
field with 2006-05-31.
IDEALLY it should create two records for ID_Clients = 20, one for period
ended 30 April 2005 and one for period ended 30 April 2006. However, that
sounds very complicated, and I would be content (for now) with one that just
creates one field to 30 April 2006 (unless the more general solution is more
trivial than I expect).
Any help or pointers would be gratefully received.
I am a real newbie to Access (I don't even know how to insert a calculated
date into a record during an action query) and John Spencer gave me a lot of
help in the gettingstarted newsgroup on a similar problem. Perhaps this
question should be addressed there but I feel it is getting a bit more
complicated, and it is query-specific so I put it here. Apologies if in
error. (John, if you read this you will recognise the previous problem.)
I have a database with 2 tables: T_Clients and T_Tasks.
T_Clients has 3 fields:
ID_Clients = autonumber, primary key
YEM = number, integer, validation permits range >0 and <13 (representing a
month)
YED = number, integer, validation permits range >0 and <32 (representing a
day in a month)
(the user is currently trusted not to enter impossible values within those
ranges, ie 31 June or 30 February)
T_Tasks has 3 fields:
ID_Tasks = autonumber, primary key
ID_Clients = number, long integer
PeriodTo = date
There is a one (T_Clients.ID_Clients) to many (T_Tasks.ID_Clients)
relationship with enforced referencial integrity.
In my sample data, T_Clients has 3 records
ID_Clients YEM YED
20 4 30
21 5 31
22 6 30
T_Tasks has 3 records
ID_Tasks ID_Clients PeriodTo
11 20 2004-04-30
12 21 2005-05-31
13 22 2006-06-30
I am needing an Append query, that creates records in T_Tasks. I don't care
how many intermediate Select Queries I need to create to get to the final
destination.
User inputs a date (call it "RollDate") and for this example say the user
input date 2006-06-30 (I am flexible about where this needs to be stored, or
whether it is input on a prompt when the append query is run).
The query then adds records to T_Tasks, by considering each instance of
ID_Clients in T_Clients and, for each such entry it adds a new period in
T_Tasks if an appropriate period does not already exist in T_Tasks for that
ID_Clients value. An appropriate period is one that ends on the latest date
on or before the RollDate but bearing the month and day-of-the-month
particular to that value of ID_Clients as specified in T_Clients.YEM and
T_Clients.YED.
So, for the sample data given:
It should ignore ID_Clients = 22, because the year end for that client is
set to 30 June, the latest such date on or before rolldate (30 June 2006)
is, coincidentally, 30 June 2006 and there already exists a record with that
date in the PeriodTo field.
It should create one record for ID_Clients = 21, and populate the PeriodTo
field with 2006-05-31.
IDEALLY it should create two records for ID_Clients = 20, one for period
ended 30 April 2005 and one for period ended 30 April 2006. However, that
sounds very complicated, and I would be content (for now) with one that just
creates one field to 30 April 2006 (unless the more general solution is more
trivial than I expect).
Any help or pointers would be gratefully received.