17

I need some help to complete this trigger. I try it but I don't know what is wrong.

This is the code:

delimiter $$

CREATE TRIGGER attendance_clock AFTER INSERT ON alldevicerecord
FOR EACH ROW
BEGIN
    DECLARE check INT;
    SET check= 1;
    IF (check % 2 == 0) THEN
      INSERT into designation(emp_id, clock_date, clock_in) VALUES (new.id, new.time, new.time);
      check  = check + 1;
    ELSE
      UPDATE designation SET clock_out = new.time WHERE emp_id = NEW.id;
      check = check + 1;
    END IF
END$$

delimiter ;


Anyone can help me please?

3
  • 2
    what is the error you are getting Commented Apr 21, 2012 at 11:12
  • what are you trying to do at all? Commented Apr 21, 2012 at 11:14
  • 1
    try set check = check + 1; Commented Apr 21, 2012 at 11:21

1 Answer 1

29
delimiter $$

CREATE TRIGGER attendance_clock AFTER INSERT ON alldevicerecord
FOR EACH ROW
BEGIN
  DECLARE `check` INT;
  SET `check` = 1;
  IF (`check` % 2 = 0) THEN
    INSERT INTO designation (emp_id, clock_date, clock_in) VALUES(new.id, new.time, new.time);
    SET `check`  = `check` + 1;
  ELSE
    UPDATE designation SET clock_out = new.time WHERE emp_id = NEW.id;
    SET `check`  = `check` + 1;
  END IF;
END$$

delimeter ;
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.