0

I'm trying to create a trigger that will only run if the condition is met.

create trigger t_free 
before insert on vacation_days
for each row 
if new.days_newtier>= 365 
then set new.free=new.days_CurrYear*(select a.rate 
from algorithm a where new.work_days between a.day1 and a.day2);

I keep getting a syntax error. The trigger works fine without the if statement.

Saad Khan
  • 25
  • 5
  • 1
    You need a `FOR EACH ROW BEGIN...END`. Look over some user-contributed examples in the manual. https://dev.mysql.com/doc/refman/5.7/en/create-trigger.html – Michael Berkowski Jan 04 '17 at 18:57
  • 1
    It looks like you also missed a compulsory `END IF` if this is MySQL. Please specify MySQL or SQLite as the syntax differs. – Michael Berkowski Jan 04 '17 at 19:01
  • Even after putting a "begin, end if, and end" it keeps stating that I am missing a semicolon after "a.day2" when if fact it is present. Is there something else that I am missing in the statement, like a declare "old as new". @MichaelBerkowski – Saad Khan Jan 04 '17 at 19:34
  • This is MySQL then? What client are you using to create the trigger? The MySQL command line client and Workbench would require you to use a `DELIMITER` to set an alternate delimiter. Other clients have their own methods of specifying it http://stackoverflow.com/questions/10259504/delimiters-in-mysql – Michael Berkowski Jan 04 '17 at 19:42

0 Answers0