Jump to content
  • 0

Sum Function in Triggered Actions


MyMelody

Question

In my table, I have a field for Expenses. Upon insert, I want to update the other table with the total sum of all expenses per user. 

I have set up a triggered action. However, I can't get it to work because I'm having this error when I use the Sum Function: An aggregate may not appear in the set list of an UPDATE statement. (error code: SQL157)

Can you please help?


Thanks. 

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Hi @MyMelody,

 

I  got the same problem with you last week. The solution I thought of is to create another table. It will be like storage of whatever I insert in the main table. In the trigger, I used that table as a reference to sum up all the expenses. 

Please see the screenshot I created:

image.png.b2047902584a75f32388f035529cdf6d.png

 

Upon Insert in the MainTbl, it will be also inserted to the Table_2 (storage table).  The total expenses is the sum of all Expenses inserted in the Table_2 per ID.

 

Hope this helps.

 

-kristina

Link to comment
Share on other sites

  • 0

Upon checking, it seems that this error occurs when you are trying to set one of your columns using the UPDATE statement with a value that uses an aggregate functions such as the SUM, MAX, or MIN. 

Therefore, it is not valid because in SQL it is impossible to use aggregate functions in update SET list. 

With this, you may try to do a use case is to add a so-called subquery (SELECT statement) and use this subquery in a JOIN. For more information,I have found a forunm post that is similar to your workflow. You may check this link as a reference: 
https://forums.caspio.com/topic/32756-task-to-update-the-parent-table-with-aggregated-values-from-the-child-table/?do=findComment&comment=83154

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...