0

I want to reach something like that:

When a data inserted it will check a date column, compare it with current date and it will write something to another column. Example:

Today 27/08/2018
Date 27/08/2018
Result: Same Day

Today 27/08/2018
Date 26/08/2018
Result: Before Today

Today 27/08/2018
Date 28/08/2018
Result: After Today

I have tried this and does not work:

//CREATE TRIGGER trigger_update_status_before_insert 
BEFORE INSERT 
ON tablex
FOR EACH ROW BEGIN
  IF (NEW.date < CURDATE()) THEN
        SET NEW.status = 'Before Today'
  END IF

  IF (NEW.date = CURDATE()) THEN
        SET NEW.status = 'Same Day'
  END IF

  IF (NEW.date > CURDATE()) THEN
        SET NEW.status = 'After Today'
  END IF
END;//

phpmyadmin delimiter: //

1
  • 1
    Every statement must be terminated. Commented Aug 27, 2018 at 18:06

1 Answer 1

0

error in your SQL syntax creating MySQL trigger @p.campbell 's answer solved the problem. I just deleted semi column and it worked.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.