How to declare variable in trigger with MySQL?

MySQL help!! Need a solution to a trigger that is not working!?

  • Trying to run a trigger for a time function for a database class , keeps generating syntax errors and have been googling all day for a solution in the SQL manual. Help please! Delimiter $$ create trigger Late after insert on signinout For each row begin If each new.OutTime > 17:30 insert into transaction values (TransactionID, ((int(Time(OutTime)-17:30)/60)+1)*20), description, Date, Receipt, New.`StudentID`) end $$ Delimiter;

  • Answer:

    I see a few errors, not sure if I caught them all though (this is untested). See 3 comments in code: Delimiter $$     create trigger Late     after insert on signinout     For each row begin         If new.OutTime > 17:30 THEN -- Removed Each, added Then             insert into transaction             (TransactionID, ((int(Time(OutTime)-17:30)/60)+1)*20),                 description, Date, Receipt, New.`StudentID`); -- Add semicolon         End If; -- Add End If    end $$ Delimiter; The link below has a somewhat similar trigger. It might help you.

Eric at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

There are some errors in you code like End If & Then missing and each after the If clause. Delimiter // CREATE TRIGGER late AFTER INSERT ON signiout FOR EACH ROW BEGIN IF new.OutTime > 17:30 THEN INSERT INTO transaction VALUES (TransactionID, ((int(Time(OutTime)-17:30)/60)+1)*20), description, Date, Receipt, New.`StudentID`); END IF /* If Statement ends here */ END //

The Biker Boy

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.