Question

I've been wrapping my head around this SQL statement I'm trying to make and I've reached a wall so to speak, if you could lend any advise as to what I am doing wrong that would be a big help. I get the error around the 2nd where statement but I dont really expect the last part of the code to work yet.

CREATE TRIGGER UpdateScores
AFTER INSERT ON CharSheet FOR EACH ROW
begin
       DECLARE id_exists Boolean;
              SELECT
              1
       INTO
              @id_exists
       FROM
              ScoresTable
       WHERE
              ScoresTable.PlayerID= NEW.PlayerID;

       IF @id_exists = 1
       THEN
           UPDATE
                  ScoresTable
           SET 
                  Exp = :New.Exp;
           WHERE 
                  ScoresTable.PlayerID = :NEW.PlayerID;
        END IF;

        IF @id_exists = 0
        THEN
         -- I don't expect this part to work yet.
          INSERT INTO ScoresTable VALUES (:New.PlayerID, :New.Race, :New.Class, :New.Exp);
        END IF;
END;
$$
Was it helpful?

Solution

The problem is in this block of code:

   THEN
       UPDATE
              ScoresTable
       SET 
              Exp = :New.Exp;
       WHERE 
              ScoresTable.PlayerID = :NEW.PlayerID;
    END IF;

Remove the semicolon at the end of the set statement.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top