I am having difficulty creating the following trigger in MySQL:
CREATE TRIGGER TRG_COMPLETE_REMINDER
AFTER UPDATE ON reminders
FOR EACH ROW
BEGIN
DECLARE
new_date DATE;
IF (NEW.complete = 1 AND recurrence <> 'NONE') THEN
CASE recurrence
WHEN '1 WEEK' THEN
SELECT INTO new_date NEW.date + INTERVAL 7 DAY;
WHEN '1 MONTH' THEN
SELECT INTO new_date NEW.date + INTERVAL 1 MONTH;
WHEN '3 MONTH' THEN
SELECT INTO new_date NEW.date + INTERVAL 3 MONTH;
END CASE;
INSERT INTO reminders (description, date, userID, complete, recurrence)
VALUES (NEW.description, new_date, NEW.userID, 0, NEW.recurrence);
END IF;
END;
The issue seems to be occurring where I attempt to declare new_date. MySQL returns the following error message:
#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 '
INTO new_date NEW.date + INTERVAL 7 DAY' at line 8
I would like this trigger to create a new reminder record when the complete attribute changes to 1. The new record should have a date greater than the original record, depending on the value stored in recurrence.