The essence of the problem: there is a trigger that when entering data, the E1/E3
table should, by Dirt_ID
find all the goods in the order and convert its total price ( Price
) to the final amount in the E3
table ( Request_sum
). There is a code, but it summarizes in general all the prices of all the goods available in all orders.
create trigger ChecksumOrder on E1_Dirt_E3_Order for insert as update E3_Order set Request_sum = (select sum(Price) from E1_Dirt i join E1_Dirt_E3_Order e on i.ID_Dirt=e.ID_Dirt) where E3_Order.ID_Order != E3_Order.ID_Order join E1_Dirt_E3_Order c on c.ID_Order=e.ID_Order go