Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8315541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:09:16+00:00 2026-06-08T21:09:16+00:00

I am trying to create a Trigger that will run through some IF ELSEIF

  • 0

I am trying to create a Trigger that will run through some IF ELSEIF statements and check the new value is NULL however it only goes to the first IF statement.

This Trigger is AFTER UPDATE. My question is if I am only SET one column value what are the others SET to, are they NULL or what. How can I test this column if it is not SET on this UPDATE command.

Example Update:

UPDATE  `stations_us`.`current_prices` SET  `midPrice` =  '3.59' WHERE  `current_prices`.`_id` =1;

There are other columns that do not update at this time but can be updated based on the 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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:09:18+00:00Added an answer on June 8, 2026 at 9:09 pm

    You can’t tell inside the trigger which columns were referenced in the SET clause.

    You can only check whether the value of col was changed by the statement, by comparing the values of NEW.col and OLD.col.

    IF NOT (NEW.regPrice <=> OLD.regPrice)
    

    Testing (NEW.col IS NOT NULL) is not sufficient to tell whether the value has been changed. Consider the case when old value is e.g. 4.95 and the new value is NULL, it looks as if you probably want to detect that change.


    Note that an UPDATE statement may set values for more than one column:

    UPDATE foo SET col1 = 'a', col2 = 'b', col3 = 'c' WHERE ...
    

    Also note that a column may be set to NULL, and a column can be set to its existing value

    UPDATE foo SET col1 = 'a', col2 = NULL, col3 = col3 WHERE ...
    

    In this case, inside your trigger, NEW.col2 would evaluate to NULL, and (NEW.col3 <=> OLD.col3) will evaluate to 1 (TRUE), because the OLD and NEW values are equal.

    (What your AFTER UPDATE trigger is really seeing is the value that got stored, which is not necessarily the value from your UPDATE statement if a BEFORE INSERT trigger has mucked with the value, and supplied a different value for that column.)

    If your intent is to log changes in values, you probably do NOT want the ELSIF, but instead want to run through all the columns to check whether it’s value has been changed or not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a BEFORE INSERT trigger that will check the incoming
I'm trying to create a trigger that will do the following. After insert on
I am trying to create some MySQL code that will invoke a Java program
I am trying to create a trigger that will update a GEOMETRY column based
All, I am just trying to create a trigger that will pick a whole
I am trying to create a Trigger, that will update the History Table with
Possible Duplicate: Reset JavaScript Counter? I'm trying to create a function that will trigger
I am trying to create a trigger wherein it will insert a new row
I'm trying to create a trigger that will associate an unique random string to
So, I'm trying to create a trigger that will throw an error on inserting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.