I am trying to create a Trigger that will run through some IF ELSEIF and check for a new NULL value, but it only applies to the first IF expression.
This Trigger is AFTER UPDATE . My question is that I only SET one column value, what others SET to, whether they are NULL or what. How can I check this column if it is not SET in this UPDATE command.
Update example:
UPDATE `stations_us`.`current_prices` SET `midPrice` = '3.59' WHERE `current_prices`.`_id` =1;
There are other columns that are not currently updated, but can be updated based on PHP Script.
Trigger:
BEGIN -- Definition start IF(NEW.regPrice IS NOT NULL) THEN INSERT INTO prices (stationID, price, type, prevPrice, prevDate, dateCreated, apiKey, uid) VALUES(NEW.stationID, NEW.regPrice, 'reg', OLD.regPrice, OLD.regDate, NEW.regDate, NEW.lastApiUsed, NEW.lastUpdatedBy); ELSEIF(NEW.midPrice IS NOT NULL) THEN INSERT INTO prices (stationID, price, type, prevPrice, prevDate, dateCreated, apiKey, uid) VALUES(NEW.stationID, NEW.midPrice, 'mid', OLD.midPrice, OLD.midDate, NEW.midDate, NEW.lastApiUsed, NEW.lastUpdatedBy); ELSEIF(NEW.prePrice IS NOT NULL) THEN INSERT INTO prices (stationID, price, type, prevPrice, prevDate, dateCreated, apiKey, uid) VALUES(NEW.stationID, NEW.prePrice, 'pre', OLD.prePrice, OLD.preDate, NEW.preDate, NEW.lastApiUsed, NEW.lastUpdatedBy); END IF; -- Definition end END