Quinn Posted October 1 Report Share Posted October 1 Hi All, I have the below SQL statement: SELECT SUM(Amount) FROM tblRepayments WHERE LoanID = [@field:LoanID] tblLoans is the parent table for tblRepayments both linked by a LoanID field. Autonumber in tblLoans and Integer in tblRepayments. The statements above should return a different value per LoanID as each loan has a different number of repayments and different repayment amounts. however, the exact same number is returned each time. Any help would be appreciated. Quote Link to comment Share on other sites More sharing options...
0 CoopperBackpack Posted October 2 Report Share Posted October 2 Hello @Quinn, Please use the 'target' keyword to get the correct result. The statement should be SELECT SUM(Amount) FROM tblRepayments WHERE LoanID = target.[@field:LoanID] You may check an example in this article under the 'Subqueries in Calculated Fields' paragraph https://howto.caspio.com/datapages/reports/advanced-reporting/calculations-in-forms-and-reports/ The part of the statement after the equal sign is a dynamic one. So, a parameter is replaced by a real value when the DataPage is loaded. The parameter in your example is [@field:LoanID] When the 'target' keyword is used the parameter is replaced with the value stored with this particular record. In your example that will be: SELECT SUM(Amount) FROM tblRepayments WHERE LoanID = 71 (for the 1st record) SELECT SUM(Amount) FROM tblRepayments WHERE LoanID = 72 (for the 2nd record), etc. Hope this helps! Quote Link to comment Share on other sites More sharing options...
0 NiceDuck Posted October 3 Report Share Posted October 3 In addition to what @CoopperBackpack said, you can also use 'target.' not only on calculated fields but on calculated values as well. When you are having doubt if your calculations is getting the proper field values, try putting that as a prefix. Quote Link to comment Share on other sites More sharing options...
0 Flowers4Algernon Posted October 21 Report Share Posted October 21 Hello! This link should also be helpful as you go along: https://howto.caspio.com/function-reference/ Quote Link to comment Share on other sites More sharing options...
Question
Quinn
Hi All,
I have the below SQL statement:
SELECT SUM(Amount) FROM tblRepayments WHERE LoanID = [@field:LoanID]
tblLoans is the parent table for tblRepayments both linked by a LoanID field. Autonumber in tblLoans and Integer in tblRepayments.
The statements above should return a different value per LoanID as each loan has a different number of repayments and different repayment amounts.
however, the exact same number is returned each time.
Any help would be appreciated.
Link to comment
Share on other sites
3 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.