Trigger on Insert, Update (SUM of another table with WHERE Clause)
Posted on 2008-10-29
Following a similar question recently raised
I have a table called quoteitems
that has product items and prices inserted.
quit_lineitemid quit_orderquoteid quit_listprice quit_commission quit_productid quit_productfamilyid
1 1 100.00 15.00 4 9
2 1 90.00 5.00 3 6
3 1 10.00 1.00 5 6
4 1 11.00 1.00 8 9
I also have another top level table called Quotes
quot_orderquoteid quot_labourcost quote_cashback
1 NULL NULL
I need that when an row is inserted or updated in the QuoteItems table that the sum of the quit_listprice is added to the Quote.quot_labourcost field where the quit_productfamilyid = '9' and the quot_cashback field is summed listprice where the quit_productfamilyid = '6'
They are joined by the quot and quit_orderquoteid and I only need to sum where the quit_deleted is null.
Cheers, help is appreciated