Very Complex Query Problem...

From: Gary B (no_at_spam.com)
Date: 10/30/04


Date: Sat, 30 Oct 2004 15:56:43 -0400

Patients
PatientsKey, PatientsName

Doctors
DoctorsKey, DoctorsID

Charges:
ChargesKey, ChargesDate

Services:
ServicesKey, ChargesKey, DoctorsKeyKey, PatCharge, InsCharge

Payments
PaymentsKey, PaymentsDate, PaymentAmount, PatOrInsPmtType(1=PatPmt;2=InsPmt)

AppliedPayments
AppliedPaymentsKey, PaymentsKey, ServicesKey, AmountApplied, PatOrInsPmtType

I want to return as follows:

select DoctorsID, PatientsName, PatDue0To30Days, InsDue0To30Days,
PatDue31To60Days, InsDue31To60Days

Thank you