0
DELIMITER //
CREATE TRIGGER sample_index
AFTER INSERT ON qa_quantifiers_box_float
FOR EACH ROW BEGIN
    IF (
        SELECT 1 = 1 
        FROM `qa_quantifiers` 
        WHERE `type`='PERCENTAGE' 
        and Id<>8 
        and Id=NEW.q_id
    ) THEN
        update qa_labels_box_gen qa set `SampleIndex`=(SampleIndex+NEW.score) WHERE NEW.qlb_id=Id;
    END IF;
END;
DELIMITER;

MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 11

enter image description here

What?

EDIT:

Got it to work thanks to ÁlvaroGonzález comment :

what i didnt know is that when using ; inside mysql code i needed to change the delimeter to // and use it after i define the trigger :

DELIMITER //
CREATE TRIGGER sample_index
    AFTER INSERT ON qa_quantifiers_box_float
    FOR EACH ROW BEGIN
        IF (
            SELECT 1 = 1 
            FROM `qa_quantifiers` 
            WHERE `type`='PERCENTAGE' 
            and Id<>8 
            and Id=NEW.q_id
        ) THEN
            update qa_labels_box_gen qa set `SampleIndex`=(SampleIndex+NEW.score) WHERE NEW.qlb_id=Id;
        END IF;
    END;
//
Ofek Ron
  • 8,354
  • 13
  • 55
  • 103
  • 2
    You miss the delimiter Setting i guess – Jens May 09 '17 at 08:20
  • If you're running the code in a SQL client that accepts multiple statements (as it seems to be the case) you need to temporarily set a new delimiter. – Álvaro González May 09 '17 at 08:22
  • What is purpose of this " SELECT 1 = 1 " – Vijunav Vastivch May 09 '17 at 08:36
  • @Jens - that didnt work either see edit – Ofek Ron May 09 '17 at 08:36
  • @ÁlvaroGonzález how? please elaborate – Ofek Ron May 09 '17 at 08:37
  • @ÁlvaroGonzález got it to work thanks to your comment thanks! – Ofek Ron May 09 '17 at 08:39
  • 1
    As a general hint, the MySQL error messages specify the piece of query where it encounters the error (*" for the right syntax to use near '...'"*). When that piece of query is empty (*"... near ''"*) then the error is at the end of the query. Many times it happens that the query is incomplete. This was also the case here; MySQL couldn't find the delimiter after the query: you changed it to `//` but you used `;` as usual after the body of the trigger. – axiac May 09 '17 at 09:03
  • I wrote an explanation for some other question. I've closed as dupe since the explanation applies just fine to almost any client. – Álvaro González May 09 '17 at 09:03

0 Answers0