if语句在触发器mysql中

时间:2012-04-21 11:11:06

标签: mysql

我需要一些帮助才能完成此触发器我尝试但我不知道出了什么问题:(我正在使用wampserver phpmysql ,,这是代码:

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;

任何人都可以帮助我????

1 个答案:

答案 0 :(得分:20)

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;

$$