Hi,
I am having problems to get expected results from the following SQL query.
As you can see, I have a column 'Amount' in the table CY for total required payment, I also have a column 'Amount' in the table P, I want to get a total paid amount(P.Amt) first from the table P, then join it with others, then I want to get records where CY.Amount is bigger than P.Amt(Outstanding payments are required). The query returns no record. It only works when I tested it with 'CY.Amount = P.Amt'
Any suggestion?
I am having problems to get expected results from the following SQL query.
As you can see, I have a column 'Amount' in the table CY for total required payment, I also have a column 'Amount' in the table P, I want to get a total paid amount(P.Amt) first from the table P, then join it with others, then I want to get records where CY.Amount is bigger than P.Amt(Outstanding payments are required). The query returns no record. It only works when I tested it with 'CY.Amount = P.Amt'
Any suggestion?
Code:
strSQL = "SELECT E.ID,CIS,FName,LName,DOB,Cycle,Sub_Num," _
& " F.Info,DateS,DateF,CY.Amount,P.Amt" _
& " FROM (((((tblER E" _
& " INNER JOIN tblClient C ON E.Client_ID=C.ID)" _
& " INNER JOIN tblERCycle CY ON E.ID=CY.ER_ID)" _
& " INNER JOIN tblRegion R ON C.Reg_ID=R.ID)" _
& " INNER JOIN ( " _
& " SELECT CycleID, SUM(Amount) AS Amt" _
& " FROM tblPayment" _
& " GROUP BY CycleID ) P ON CY.ID=P.CycleID)" _
& " INNER JOIN tblFunding F ON CY.Fund_ID=F.ID)" _
& " WHERE CY.Amount > P.Amt" _
& " ORDER BY DateF ASC"