Jump to content
  • 0

SELECT SUM(Amount) FROM tblRepayments WHERE LoanID = [@field:LoanID] ........returns same number no matter the loanID ??


Quinn

Question

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.

1.PNG

2.PNG

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

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!

Link to comment
Share on other sites

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.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...