Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42477

Join table Problem

$
0
0
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?

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"


Viewing all articles
Browse latest Browse all 42477

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>