Need help with shifting data

A

Al

The data below is a union qry from 2 tables (tblMedication and
tblVitalSigns). I am trying to prepare the data for a report. However, I have
to get the body wt from the Vital sings table row added to the row coming
from tblMedication, in the following fashion:
1) For each patient there are records with body wt in the tblvitalsigns and
records with Medicationtype, frequency from tblMedication. both tables have
the dateofexam
2) I want to take the body wt from the tblvitalsigns row (row without
Medicationtype nor Medication frequency) and place it in the row from
tblmedication (the row, with Medicationtype and MedicationFrequency, not
null).
3) after populating the tblmedication rows, in the qry, in that fashion, I
want to filter out the blank rows (tblvitalsigns rows). this last part is
easy but I am having trouble fixing the first part due to the following.

1) not every date is duplicated in both tables (see data below). this is
causing inconsistency when I use subquery to pull the data. here is the sub
qry that I used:
****************************
DBodyWt: (Select BodyWt as BWT From Dosage_VS as DBT Where
DBT.PatientID=Dosage_VS.PatientID and DBT.MedicationType is null and
Dosage_VS.MedicationType is not null AND ((Dosage_VS.DateofExam>DBT.PDate) OR
(Dosage_VS.DateofExam<DBT.NDate)) AND Dosage_VS.DateofExam=DBT.nDate)
******************************
PDate and NDate are the previous and next date. I used another subqry to get
these dates.
PDate example:
****************************
PDate: (Select Max(DateofExam) as TreatmentDate From DosageTest as DT Where
DT.PatientID=DosageTest.PatientID and DT.DateofExam<DosageTest.DateofExam)
*****************************
Sample data:

PatientID MedicationType DateofExam MedicationFrequency BodyWt
004444 5/8/1996
87.8
004444 A10 iv 5/8/1996 6
004444 5/9/1996
89
004444 A10 iv 5/9/1996 6
004444 5/10/1996
89
004444 5/15/1996
91
004444 5/16/1996
90
004444 A10 iv 5/16/1996 6
004444 5/17/1996
92.75
004444 A10 iv 5/17/1996 6
004444 6/19/1996
110
004444 A10 iv 6/25/1996 5
004444 A10 iv 6/26/1996
004444 A10 iv 6/28/1996 6
004444 A10 iv 6/29/1996 6
004444 A10 iv 7/2/1996 6
004444 7/17/1996
113
004444 A10 iv 8/3/1996
004444 A10 iv 1/27/1998 6
004444 3/25/1998
141
004444 A10 iv 3/25/1998
004444 6/1/1998
125.5
004444 8/20/1998
129
004444 10/29/1998
126
004444 2/15/1999
125
004444 10/15/2004
175
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top