1

I have this MYSQL EVENT which I can't understand why it not works. It shows me an error saying "Sorry an unexpected error happened!" on phpmyadmin when I'm trying to execute it. Please someone tell me what is wrong with this code.

DELIMITER //
CREATE EVENT salary_add
  ON SCHEDULE EVERY 24 HOUR
  DO
  BEGIN
  DECLARE month_end DATETIME;
  SET month_end = LAST_DAY(DATE(NOW()));
  DECLARE today DATETIME;
  SET today = DATE(NOW());
  DECLARE reg_id VARCHAR(6);
  DECLARE sal INT(8);

   IF month_end=today THEN
   SELECT register_id INTO reg_id, salary INTO sal FROM employees 
   WHERE status ='1';
   INSERT INTO tbl_salary values register_id=reg_id,amount=sal,salary_date=today,status='0';
   END IF;
   END//
 DELIMITER ;
ashen25
  • 29
  • 7
  • 1
    1) Set statement should appear after declare statements, 2) select into format is incorrect - should be select col1,col2 into var1,var2 (see manual https://dev.mysql.com/doc/refman/8.0/en/select-into.html) 3) you may get an error if more than 1 value is returned by select (see same manual) Hint - I always write as procedure first to debug and then convert to an event – P.Salmon Sep 12 '18 at 06:31
  • Thnx @P.Salmon, I fixed the error in code, it works fine. In the manual it dosen't say what to do if I needed to select multiple rows. What I actually want to do is select multiple rows data and insert those in the second table as a batch. I figured that it cannot achiev by the above code. How can I do this? – ashen25 Sep 12 '18 at 07:47
  • So now you have a completely different question? – Joakim Danielson Sep 12 '18 at 08:25
  • Thnx.. I got it to work.. – ashen25 Sep 12 '18 at 09:01

0 Answers0