Dear Al:
I see that the BodyWt values all come from tblVitalSigns, while the
DailyDose and MedicationFrequancy come only form tblSteroids. The
solution
may be easier without the UNION query.
In order to form the type of JOIN I have in mind, we need to find the
DateOfTreatment from tblSteroids for each row in tblVitalSigns. That
date
will be the same date, or the most recent previous date. I believe that
would be:
SELECT PatientID, DateOfExam, st_MedicationVol, st_MedicationFrequancy,
(SELECT MAX(DateOfExam) FROM tblVitalSigns V
WHERE V.PatientID = S.PatientID AND V.DateOfExam < S.DateOfExam) AS
LDate
FROM tblSteroids S
Does this query correctly return the date for the VitalSigns exam to be
associated with each Steroids record?
I am concerned there may be missing dates. This could reflect a
condition
where there are rows for a patient in tblSteroids for which there is no
previously dated row in tblVitalSigns. According to your instructions,
as I
understand them, this would be expected if that were to happen.
I will refer to this as Query1, assuming you will save that query.
You can then JOIN the tblSteroids to Query1 to get everything you need.
SELECT Q.PatientID, Q.st_DateofExam, Q.st_MedicationVol,
Q.st_MedicationFrequancy,
V.DateOfExam, V.BodyWt
FROM Query1 Q
INNER JOIN tblVitalSigns V
ON V.PatientID = Q.PatientID AND V.DateOfExam = Q.LDate
After you get it working, add to this query your forms based filters and
the
sorting.
Does this begin to produce what you wanted? Please let me know if this
helped, and if you need any other assistance.
Tom Ellison
Al said:
Sorry forgot to paste the sql. here it is:
*************************************
SELECT [PatientID],[st_DateofTreatment] as [EventDate],"" as
[BodyWt],[st_MedicationVol] as [DailyDose(ml)],[st_MedicationFrequancy]
as
[Frequancy]
FROM tblSteroids
where PatientID = [Forms]![frmSteroidsMain]![PatientID] and
[st_DateofTreatment]>= [Forms]![frmSteroidsMain]![ProtocolStartDate]
and
[st_DateofTreatment]<[Forms]![frmSteroidsMain]![ProtocolWithdrawlDate]
UNION ALL SELECT [PatientID],[DateofExam] as [EventDate],[BodyWt],""
as
[DailyDose(ml)],"" as [Frequancy]
FROM tblVitalSigns
where PatientID = [Forms]![frmSteroidsMain]![PatientID] and
[DateofExam]>=
[Forms]![frmSteroidsMain]![ProtocolStartDate] and [DateofExam]<
[Forms]![frmSteroidsMain]![ProtocolWithdrawlDate]
ORDER BY [EventDate];
*********************************************
:
Dear Al:
I'll assume the "missing" body weight values are null and that this
column
is numeric.
There would be a good way of doing this, except that your data is
ambiguous.
You have a weight of 64 that has been entered for the missing weight
dated
4/1/1996. Why couldn't the missing weight be filled by the 60 value
of
that
same date? In reality, this might be more realistically accurate.
Since
the data you show does not allow me to see any unique ordering of the
rows,
so it is hard to see why the 6th row and 7th row could not trade
places.
In writing a query to do this, such questions are critical.
In order to retrieve any missing BodyWt values, you would need to use
a
subquery. If you will post the SQL text of the query you have for the
sample you showed, I'll try to add the missing portion. If you don't
answer
the questions I asked above, I suppose I would just arbitrarily choose
one
method out of many possible methods, all of which potentially produce
different results.
Another question would be whether you could ever have two rows with
the
same
weight on the same date.
Finally, I'd like to suggest you could prorate the BodyWt between the
weights given. In the sample data, the weight would decrease by 4
over
the
period of 6 days between the first two measurements, being about .7
per
day.
This would be more realistic I expect, but you must then prohibit any
possibility of having 2 weights on the same date.
Tom Ellison
I have the following union query:
PatientID EventDate BodyWt DailyDose(ml) Frequancy
004320 3/26/1996 64
004320 3/27/1996 20 6
004320 3/28/1996 30 6
004320 3/30/1996 40 6
004320 3/31/1996 50 6
004320 4/1/1996 60 6
004320 4/1/1996 60
004320 4/2/1996
004320 4/2/1996
004320 4/11/1996 62.6
I need to accomplish the following:
I need to carry on the bodywt to fill in the blank records to look
like
the
following:
PatientID EventDate BodyWt DailyDose(ml) Frequancy
004320 3/26/1996 64
004320 3/27/1996 64 20 6
004320 3/28/1996 64 30 6
004320 3/30/1996 64 40 6
004320 3/31/1996 64 50 6
004320 4/1/1996 64 60 6
004320 4/1/1996 60
004320 4/2/1996 60
004320 4/2/1996 60
004320 4/11/1996 62.6
Can someone help.
thanks
Al