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