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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:30:23+00:00 2026-06-09T04:30:23+00:00

I really hope you can help me solve this issue.. I am trying to

  • 0

I really hope you can help me solve this issue.. I am trying to run two different kinds of update query based on whether the old fields length was greater than one or not. The idea behind this is that when a user updates a product, it will append the ProductRef to the Search table which is used purely for searching.

So simply, if the string length of ProductRef is greater than 0, replace the old product ref with the new one. Otherwise, add the new product ref. Here is what I have so far but it seems to trigger an error –

-- Update the ProductType UpdatedTS that corresponds with this product
-- The below section simply updates the main products UpdatedTS
UPDATE tbl_product_types 
SET UpdatedTS = now() 
WHERE ID = New.ProductTypeID;

IF ( SELECT Length(Old.ProductRef) > 0 )
    BEGIN
        -- We have already stored the product reference so run a replace
        UPDATE tbl_product_type_search AS STable
        SET `STable.Search` = replace(`Search`,CONCAT(Old.ProductRef,' '),New.ProductRef) 
        WHERE `STable.ProductTypeID` = Old.ProductTypeID
    END
ELSE
    BEGIN
        -- We haven't yet stored the product reference, store it
        UPDATE tbl_product_type_search AS STable
        SET `STable.Search` = CONCAT(NEW.ProductRef,' ',`STable.Search`) 
        WHERE STable.ProductTypeID = New.ProductTypeID
    END

For your reference, here is the relevant DB structure:

Database Structure

  • 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-09T04:30:25+00:00Added an answer on June 9, 2026 at 4:30 am

    It seems that it is UPDATE trigger. Isn’t it? If so, try this code (there were some syntax errors) –

      UPDATE
        tbl_product_types
      SET
        UpdatedTS = NOW()
      WHERE ID = NEW.ProductTypeID;
    
      IF (SELECT length(Old.ProductRef) > 0) THEN
        -- We have already stored the product reference so run a replace
        UPDATE
          tbl_product_type_search AS STable
        SET
          `STable.Search` = REPLACE(`Search`, CONCAT(Old.ProductRef, ' '), NEW.ProductRef)
        WHERE
          `STable.ProductTypeID` = OLD.ProductTypeID;
      ELSE
        -- We haven't yet stored the product reference, store it
        UPDATE
          tbl_product_type_search AS STable
        SET
          `STable.Search` = CONCAT(NEW.ProductRef, ' ', `STable.Search`)
        WHERE
          STable.ProductTypeID = NEW.ProductTypeID;
      END IF;
    

    Two UPDATE statements into one:

    UPDATE
      tbl_product_type_search AS STable
    SET
      `STable.Search` =
        IF(
          LENGTH(OLD.ProductRef) > 0,
          REPLACE(`Search`, CONCAT(OLD.ProductRef,' '), NEW.ProductRef),
          CONCAT(NEW.ProductRef, ' ', `STable.Search`)
        )
    WHERE
      LENGTH(OLD.ProductRef) > 0 AND `STable.ProductTypeID` = OLD.ProductTypeID
      OR
      LENGTH(OLD.ProductRef) <= 0 AND STable.ProductTypeID = NEW.ProductTypeID
    

    About delimiters:

    DELIMITER $$
    
    CREATE TRIGGER trigger_name
    AFTER UPDATE
    ON table_name
    FOR EACH ROW
    BEGIN
    
      UPDATE tbl_product_types...;
    
      other statements...;
    END
    $$
    
    DELIMITER ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I really hope someone can help me with this. Basically i have an issue
I really hope someone can help on this because I'm learning cocoa and have
I really hope someone can help with this problem. I have an ajax pagination
I really hope someone can help me with this. I'm struggling with it for
I'm driving myself nuts with this particular problem, i really hope someone can help!
I really hope someone can help me along with this one... I need to
I really hope you can help out here. I'm creating a theme for a
I'm almost losing it, i really hope someone can help me out! I'm using
I have a really hard time understanding routes and I hope someone can help
I'm really confused so I hope you guys can help me. I know how

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.