I cannot get this trigger code to compile on MySQL 5.3:
CREATE TRIGGER crmenq_bur
BEFORE UPDATE
ON crmenquiries
FOR EACH ROW
BEGIN
IF ( NEW.feedback = OLD.feedback
AND NEW.notes = OLD.notes
AND NEW.estatus = OLD.estatus )
THEN
SET NEW.update_type = 'NN';
ELSE
SET NEW.update_type = 'SEN';
SET new.last_update2 = now();
END IF;
CASE
WHEN NEW.estatus != OLD.estatus AND NEW.estatus = 'FP3' THEN
SET NEW.uid_follow_up = NEW.uid_last_update_by;
SET NEW.follow_up_date = DATE_ADD ( date(), INTERVAL 3 MONTH );
WHEN NEW.estatus != OLD.estatus AND NEW.estatus = 'FP6' THEN
SET NEW.uid_follow_up = NEW.uid_last_update_by;
SET NEW.follow_up_date = DATE_ADD ( date(), INTERVAL 6 MONTH );
WHEN NEW.estatus != OLD.estatus AND NEW.estatus = 'FP9' THEN
SET NEW.uid_follow_up = NEW.uid_last_update_by;
SET NEW.follow_up_date = DATE_ADD ( date(), INTERVAL 9 MONTH );
WHEN NEW.estatus != OLD.estatus AND NEW.estatus = 'FP12' THEN
SET NEW.uid_follow_up = NEW.uid_last_update_by;
SET NEW.follow_up_date = DATE_ADD ( date(), INTERVAL 12 MONTH );
WHEN NEW.estatus NOT IN ( 'FP3', 'FP6', 'FP9', 'FP12' ) THEN
SET NEW.uid_follow_up = NULL;
SET NEW.follow_up_date = NULL;
END CASE;
END;
When I run this I get the following error:
[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 '), INTERVAL 3 MONTH ); WHEN NEW.estatus != OLD.estatus AND NEW.estatus = ' at line 18]
Initially I had nested IF but changed to CASE to see if that made any difference. The current form is not how I had it originally (nested IF to avoid repeating the same condition) but with each unsuccessful attempt the code was changed but nothing I have tried has worked.
The column/tables names are correct.