Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7782137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:26:51+00:00 2026-06-01T19:26:51+00:00

I am creating a trigger to Update a column TEST if column receipt_on =

  • 0

I am creating a trigger to Update a column TEST if column receipt_on = Quarterly Interest
Then If so it should find the sum in column receipt_amount and join another table loan
on column l_app_file_id from table Loan on column r_app_file_id from table receipt_history
also the month name from column receipt_date from table receipt_history should be the same as the current month, however I am not sure as to how to entirely structure this trigger

-- Trigger DDL Statements
DELIMITER $$

USE `lms`$$

CREATE
DEFINER=`root`@`localhost`
TRIGGER `lms`.`updateloan`
BEFORE UPDATE ON `lms`.`receipt_history`
FOR EACH ROW
BEGIN

if new.receipt_on='Quarterly Interest' then 
    SET new.TEST=SUM(receipt_amount)
    join loan l on 
    l.l_app_file_id=r.r_app_file_id
    WHERE r_app_file_id=l_app_file_id
    and monthname(receipt_date)=MONTHNAME(now())
    end if;    

  END$$
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:26:52+00:00Added an answer on June 1, 2026 at 7:26 pm

    As you now know you cannot join in a set statement.
    You need to use a select statement for that.
    This construct will work however set i:= (select sum(x) from a);
    I personally prefer the SELECT something INTO avariable syntax, but that’s just a matter of taste.

    DELIMITER $$
    
    USE `lms`$$
    
    CREATE
    DEFINER=`root`@`localhost`
    TRIGGER `lms`.`updateloan`
    BEFORE UPDATE ON `lms`.`receipt_history`
    FOR EACH ROW
    BEGIN
      DECLARE itest integer;
    
      if new.receipt_on='Quarterly Interest' then 
        SELECT SUM(r.receipt_amount) INTO itest FROM receipt_history r
        INNER JOIN loan l ON (l.l_app_file_id=r.r_app_file_id)
        WHERE monthname(r.receipt_date)=MONTHNAME(now());
        SET new.test = itest;
      end if;    
    
      END$$
    

    Note that:
    the join criterion is already a (kind of) where clause, so you don’t have to repeat that in the where clause.
    Each and every statement in the trigger needs to be terminated by a ;.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a trigger in SQL Server after INSERT, UPDATE and DELETE. Is there
I'm creating the following trigger: CREATE TRIGGER Trigger_UpdateTrainingDelivery AFTER DELETE OR INSERT OR UPDATE
I am creating an After Update Trigger on a SQL Server 2008 table. The
I'm creating a trigger for a table, and I have the following statement: UPDATE
I was looking at creating a TRIGGER that will set the value of a
I'm having a problem creating a trigger on a database for a project I've
I'm using SQL Server 2008. I'm creating a DDL trigger like this: CREATE TRIGGER
I have problem with creating a simple MySQL trigger in C#. I'm using StringBuilder
I am studying the trigger and I got a question. I am creating a
I'm creating a stored procedure that will create 3 triggers (insert, update, delete) given

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.