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 3844318
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:04:14+00:00 2026-05-19T16:04:14+00:00

I need to create a trigger that computes one column value based on other

  • 0

I need to create a trigger that computes one column value based on other column values. A database is a little bit denormalized to get higher performance. (Normalization is not an issue of this question).

The problem is that I want to set value of computed_address value and it is ok if i put a constant in it. But it seems that these If clauses aren’t working and I just can’t see the problem.

Below is the trigger code.
Thank you very much!

DELIMITER $$

USE `nth_poi_new_3`$$

DROP TRIGGER /*!50032 IF EXISTS */ `poi_address_creator`$$

CREATE
    /*!50017 DEFINER = 'root'@'localhost' */
    TRIGGER `poi_address_creator` BEFORE INSERT ON `poi` 
    FOR EACH ROW BEGIN
    DECLARE full_address VARCHAR(255);
    DECLARE country_string VARCHAR(100);
    DECLARE region_string VARCHAR(100);
    DECLARE town_string VARCHAR(100);
    DECLARE address_string VARCHAR(100);

    IF NEW.address <> '' THEN   
        SET full_address = CONCAT(NEW.address, ",");

    END IF;
    IF NEW.town_name IS NOT NULL THEN
        SET full_address = CONCAT(full_address, NEW.town_name, ",");
    ELSEIF NEW.town_id IS NOT NULL THEN
        SELECT NAME INTO town_string FROM town WHERE town.town_id = NEW.town_id LIMIT 1;
        SET full_address = CONCAT(full_address, town_string, ",");
    END IF;

    IF NEW.region_name IS NOT NULL THEN
        SET full_address = CONCAT(full_address, NEW.region_name, ",");
    ELSEIF NEW.region_id IS NOT NULL THEN
        SELECT NAME INTO region_string FROM region WHERE region.region_id = NEW.region_id LIMIT 1;
        SET full_address = CONCAT(full_address, region_string, ",");
    END IF;

    IF NEW.country_name IS NOT NULL THEN
        SET full_address = CONCAT(full_address, NEW.country_name, ",");
    ELSEIF NEW.country_id IS NOT NULL THEN
        SELECT NAME INTO country_string FROM country WHERE country.country_id = NEW.country_id LIMIT 1;
        SET full_address = CONCAT(full_address, country_string, ",");
    END IF;

    SET NEW.computed_address = full_address;

    END;
$$

DELIMITER ;
  • 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-05-19T16:04:15+00:00Added an answer on May 19, 2026 at 4:04 pm

    Hey,
    just to answer. I had to initialize full_address variable first. I just made this:

    DECLARE full_address VARCHAR(255);
    

    But after declaration it needed to be initialization also:

    SET full_address="";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create trigger in SQL Server 2008 that gone insert all values
I need to create a Trigger that fires when a child record (Codes) is
I need to create Trigger for delete action which backsup all fields old value
I need to create a trigger that writes changes in a shadow table. I
I need to change this trigger to point to the column that just got
Hi guys I need to create a trigger in ORACLE 10g which ensures that
Below is trigger that I need to create but It is not getting created.Please
I need to write a trigger that will create a record in another table.
I need to create a before insert trigger on TABLE1 such that it inserts
I'm working with wordpress and need to create a trigger that updates a table

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.