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?
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With