Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger - Syntax Error #1064 new/old [closed]

Tags:

mysql

What mistake did I make here?

CREATE TRIGGER total BEFORE UPDATE ON `current` FOR EACH ROW
BEGIN
if new.`new_pay_date` <> old.`new_pay_date`
  SET new.`total_cash` = new.`curr_cash` + new.`total_cash`;
end if;
END;
$$

Error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET new.`total_cash` = new.`curr_cash` + new.`total_cash`; end if;' at line 4

This was working without

if new.`new_pay_date` <> old.`new_pay_date`
end if;

But I need to check this, and only update with date change.

current table:

curr_cash
new_pay_date
id_person
id_thing
total_cash

Anyone can help me with this one?

like image 655
Adrian Mietlowski Avatar asked May 07 '26 00:05

Adrian Mietlowski


1 Answers

Try adding THEN at the end of the if statement:

IF new.`new_pay_date` <> old.`new_pay_date` THEN
    SET new.`total_cash` = new.`curr_cash` + new.`total_cash`;
END IF;
like image 88
user1864034 Avatar answered May 09 '26 14:05

user1864034



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!