Johanna said:
OK, but append queries??? I only want 9 rows in the table so that they get
overwritten for each new immunization record.
The structure is: each kid has 8-10 different immunizations, each kind of
immunization is a separate record with places for up to 9 dates. So each
time I read a new immunization record I need to re-populate that table.
This
includes clearing any lines for which there are no dates in the new
record.
Hope this is clear!
Our point is that having 9 fields that can hold dates in a single row is
wrong.
Rather than having 1 record
ChildID ImmunizationID ImmunDate1 ImmunDate2 ImmunDate3 ImmunDate4
....
123 XYZ 2002-03-22 2003-02-11
2004-03-02 2005-03-12 ...
you should have 4 records
ChildID ImmunizationID ImmunDate
123 XYZ 2002-03-22
123 XYZ 2003-02-11
123 XYZ 2004-03-02
123 XYZ 2005-03-12
That means you need to transform the existing data. You can use a UNION
query to do that:
SELECT ChildID, ImmunizationID, ImmunDate1 As ImmunDate
FROM MyTable
UNION
SELECT ChildID, ImmunizationID, ImmunDate2
FROM MyTable
UNION
SELECT ChildID, ImmunizationID, ImmunDate3
FROM MyTable
UNION
....
UNION
SELECT ChildID, ImmunizationID, ImmunDate9
FROM MyTable
In fact, that UNION query could form the basis of the only Append query
required to get the data into the properly designed table.