Run if-else block in a trigger - MySQL

44 views Asked by At

I want to create a logical(if-else) MySQL trigger. I'm creating a trigger using PHPMyAdmin GUI. But when I'm trying to save the trigger I'm getting SQL error.

Here is my code which I want to run into that trigger:

DECLARE id integer;
DECLARE changelogid integer;

SET @id = INSERT INTO `test_assessment_data_changelog`(assignment_id,
 parameter_id, assessor_id, assessment_value) 
values(1, 1, 101, 'new');

SET @changelogid = SELECT `id` FROM `test_assesseement_data` 
WHERE `changelog_id` = @id;

IF @changelogid=null THEN
   UPDATE `test_assesseement_data`
    SET `value` = 'new' WHERE `changelog_id` = @changelogid;
ELSE
   INSERT INTO `test_assesseement_data`(`changelog_id`,
    `value`) values(@changelogid, 'new');
END IF;

Thanks

0

There are 0 answers