使用变量插入后,MySQL会触发语法错误

时间:2014-09-26 20:00:56

标签: php mysql triggers

我正在尝试根据通过的新交易跟踪用户销售情况。交易是通过我们的网站而不是他们的桌面应用程序分配的。它给了我一个语法错误,但我似乎无法找出原因。

这是我的代码:

DROP TRIGGER IF EXISTS AssignTrans;
DELIMITER $$
CREATE TRIGGER `testing_cake3`.`AssignTrans` AFTER INSERT ON `main_1` FOR EACH ROW
    BEGIN
      SET @t1 = (SELECT team_id FROM team_assignments WHERE team_assignments.misc_id = NEW.CUSTOMER_ID AND team_assignments.type = 1);
      SET @t2 = (SELECT team_id FROM team_assignments WHERE team_assignments.misc_id = NEW.GROUP_ID AND team_assignments.type = 0);
      IF (@t1) THEN
          INSERT INTO team_trans (team_id, trans_id, type, misc_id) VALUES (@t1, NEW.id, 0, 1 );
      ELSE IF (@t2) THEN
          INSERT INTO team_trans (team_id, trans_id, type, misc_id) VALUES (@t2, NEW.id, 0, 1 );
      END IF;
    END $$
DELIMITER ;

1 个答案:

答案 0 :(得分:0)

答案是改变ElSEIF的方式