Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating an Order from a trigger

Status
Not open for further replies.

Lekar

Programmer
Sep 7, 2001
85
CR
Hi.

I've a table Order with a field TotalAmount and another table called Order_Detail. I want to use a trigger on this last table, when I insert, update or delete a product the Total field from its parent table (Order) will have the sum of the products. I've tried with this script:

Alter Trigger tri_Amount On Order_Detail
After Insert, Update, Delete
As
Set NoCount On

Update [Order]
Set TotalAmount = TotalAmount + IsNull(Inserted.ItemAmount, 0) - IsNull(Deleted.ItemAmount, 0)
From Inserted
Full Outer Join Deleted
On Inserted.OrderDetailID = Deleted.OrderDetailID
Join [Order] On Inserted.OrderID = [Order].OrderID

Go

But I've problems when I delete a row, or when I update several rows in just only one Update statement.

Thanks in advance.
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top