MySQL Forums
Forum List  »  Triggers

UPDATE FROM SELECT IN TRIGGER
Posted by: Mark Wilson
Date: March 27, 2009 05:23PM

Below is an excerpt from an AFTER UPDATE TRIGGER that I have created on the table carrier_rates. My goal here is to update information in the lowest_carrier_rates table based on the results of the SELECT from the carrier_rates table. The statement works just fine outside of my trigger but when added to my trigger and then attempting to update a carrier_rates record I receive the following error message: "Can't update table 'carrier_rates' in stored function/trigger because it is already used by statement which invoked this stored function/trigger."

While I understand what the error message is staying - technically speaking this update statement is NOT updating the table 'carrier_rates' but rather only selected data from it. Any help is mucho appreciato for this newbie..maybe I need to be selecting the data in a different way? Thanks in advance for any help on this.

CODE:

UPDATE lowest_carrier_rates a, carrier_rates c
SET a.carrier_rate_id = c.carrier_rate_id, a.rate_type = CASE WHEN c.intrastate_rate IS NULL THEN 'A' ELSE CASE WHEN c.intrastate_rate < c.interstate_rate THEN 'B' ELSE 'A' END END WHERE a.npa = c.npa AND a.nxx = c.nxx AND c.npa = NEW.npa AND c.nxx = NEW.nxx;

Options: ReplyQuote


Subject
Views
Written By
Posted
UPDATE FROM SELECT IN TRIGGER
4911
March 27, 2009 05:23PM
1736
April 16, 2009 05:55AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.