MySQL Forums
Forum List  »  Triggers

Trigger to update a value
Posted by: Paul Grimes
Date: March 19, 2018 06:55AM

Hi All.
I have a table called material and in here I have the following
id (key and AI)
Title
Job_No
Quantity
Unit_Price
TotalLineValue

When I add items it basically multiply's the Quantity by the Unit Price and puts it in the TotalLineValue

I also have a table called a
In this I have the following
id (key and AI)
Job_No
MatTot

And i have this trigger

CREATE TRIGGER `NewTrigger` AFTER INSERT ON `material`
FOR EACH ROW UPDATE new_db_2005.a
SET a.MatTot =
(SELECT SUM(TotalLineValue)
FROM material
WHERE Job_No = a.Job_No)
WHERE a.id = NEW.id

So when a new value is added to the materials it will update the MatTot in table a where the Job_No is the same?

Is this possible?

Thanks

Options: ReplyQuote


Subject
Views
Written By
Posted
Trigger to update a value
1566
March 19, 2018 06:55AM
727
March 19, 2018 11:10AM
922
March 19, 2018 11:27AM
701
March 22, 2018 10:31AM


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.