As u see in the queries below, when running the 2nd query the result will be: PatientId, LastName, FirstName, TotalSumPayed and
Debt: (TblHostelInfo].EconomyPayment-QryEconomyPaymentDebt.TotalSumPayed).
I would like to "upgrade" the query. If the patient didn't pay any kind of fee to EconomyPayment, the query will show that he has 0 TotalSumPayed in the specific month. However for example, if the patient's "DateOfEnterance" is 28/06/2002, he won't have debts for the 5/2002 and less.Of course, the patient won't have debts for the 09/2002 (its in the future
).
Just for the record, Payments Takes place each month.
Moreover, the current query shows only the one's who paid and not the one's who didn't.
In my current DB there are the following Tables and Queries
TblPatient :
PatientId
LastName
FirstName
HostelId
DateOfEnterance (the date the patient entered)
TblEconomyPayment :
EconomyPaymentId
PatientId
ReferenceId
PamentDate
PaymentMethod
SumPayed
PaymentForMonth (for what month within the year did the patient payed)
PaymentForYear (for what year did the patient payed)
TblHostelInfo :
EconomyPayment ( the price needed to pay each month)
QryEconomyPaymentDebt1 :
SELECT TblEconomyPayment.PaymentForYear, TblPatient.FirstName, TblEconomyPayment.PaymentForMonth, TblPatient.LastName, TblPatient.PatientId, TblPatient.CurrentStatus, Sum(TblEconomyPayment.SumPayed) AS TotalSumPayed
FROM TblPatient INNER JOIN TblEconomyPayment ON TblPatient.PatientId = TblEconomyPayment.PatientId
GROUP BY TblEconomyPayment.PaymentForYear, TblPatient.FirstName, TblEconomyPayment.PaymentForMonth, TblPatient.LastName, TblPatient.PatientId, TblPatient.CurrentStatus;
QryEconomyPaymentDebt2:
SELECT [TblHostelInfo].EconomyPayment-QryEconomyPaymentDebt.TotalSumPayed AS Debt, QryEconomyPaymentDebt.PaymentForYear, QryEconomyPaymentDebt.FirstName, QryEconomyPaymentDebt.PaymentForMonth, QryEconomyPaymentDebt.LastName, QryEconomyPaymentDebt.CurrentStatus, QryEconomyPaymentDebt.PatientId, QryEconomyPaymentDebt.TotalSumPayed
FROM QryEconomyPaymentDebt, TblHostelInfo ;

Debt: (TblHostelInfo].EconomyPayment-QryEconomyPaymentDebt.TotalSumPayed).
I would like to "upgrade" the query. If the patient didn't pay any kind of fee to EconomyPayment, the query will show that he has 0 TotalSumPayed in the specific month. However for example, if the patient's "DateOfEnterance" is 28/06/2002, he won't have debts for the 5/2002 and less.Of course, the patient won't have debts for the 09/2002 (its in the future

Just for the record, Payments Takes place each month.
Moreover, the current query shows only the one's who paid and not the one's who didn't.
In my current DB there are the following Tables and Queries
TblPatient :
PatientId
LastName
FirstName
HostelId
DateOfEnterance (the date the patient entered)
TblEconomyPayment :
EconomyPaymentId
PatientId
ReferenceId
PamentDate
PaymentMethod
SumPayed
PaymentForMonth (for what month within the year did the patient payed)
PaymentForYear (for what year did the patient payed)
TblHostelInfo :
EconomyPayment ( the price needed to pay each month)
QryEconomyPaymentDebt1 :
SELECT TblEconomyPayment.PaymentForYear, TblPatient.FirstName, TblEconomyPayment.PaymentForMonth, TblPatient.LastName, TblPatient.PatientId, TblPatient.CurrentStatus, Sum(TblEconomyPayment.SumPayed) AS TotalSumPayed
FROM TblPatient INNER JOIN TblEconomyPayment ON TblPatient.PatientId = TblEconomyPayment.PatientId
GROUP BY TblEconomyPayment.PaymentForYear, TblPatient.FirstName, TblEconomyPayment.PaymentForMonth, TblPatient.LastName, TblPatient.PatientId, TblPatient.CurrentStatus;
QryEconomyPaymentDebt2:
SELECT [TblHostelInfo].EconomyPayment-QryEconomyPaymentDebt.TotalSumPayed AS Debt, QryEconomyPaymentDebt.PaymentForYear, QryEconomyPaymentDebt.FirstName, QryEconomyPaymentDebt.PaymentForMonth, QryEconomyPaymentDebt.LastName, QryEconomyPaymentDebt.CurrentStatus, QryEconomyPaymentDebt.PatientId, QryEconomyPaymentDebt.TotalSumPayed
FROM QryEconomyPaymentDebt, TblHostelInfo ;
