Monday, February 13, 2012

A little help..PLEASE

I have been working on this for a while and just can't seem to figure out a way to make it work. Let me explain what I need to do. I have 2 tables, Patient and PatientCharges. There is one record for each patient in the Patient table, but there may be multiple records per patient in the patient charges table, representing each time the patient has visited the doctor. What I need to do is find the oldest date of service for each patient in the patientcharges table and place that value in the first visit date field for each patient in the patient table.

Patient Table
Patient_number Last_Name First_Name First_Visit_Date
108 Drews Mike 01/01/1899
205 Samms Deb 01/01/1899

Patient Charges Table
Patient_number Date_of_Service
108 01/15/1996
108 01/29/1996
108 02/15/1996
108 10/01/1997
205 05/10/1998
205 06/12/1998
205 07/20/2000

Thanks in advance for all help. It is greatly appreciated.This is poor design, and you'll regret doing it if you use the system very long.

With that said, the solution is simple.UPDATE Patient
SET date_first_visit = (SELECT Min(date_of_service)
FROM PatientCharges
WHERE 0 = PatientCharges.PatientNumber - Patient.PatientNumber)-PatP|||WHERE 0 = PatientCharges.PatientNumber - Patient.PatientNumber
Why do you write 0 = a - b instead of a = b ?|||Read his post. He said it was a poor design, didn't he?

Sorry Pat, couldn't resist... ;)

No comments:

Post a Comment