Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Can't Update another table with trigger

Author  Topic 

azim
Starting Member

29 Posts

Posted - 2005-02-14 : 06:02:42
I want to update balance on tblProducts from tblInventory_Det
but this Trigger does't work
I update the dataset from Datagrid
please help
[CODE]
CREATE TRIGGER UpdateBalance_In ON dbo.tblInventory_Det
FOR UPDATE,INSERT,DELETE
AS

BEGIN
UPDATE tblProducts
SET Balance =Balance + Inserted.InQuantity

FROM tblInventory_Det

INNER JOIN Inserted

ON (tblInventory_Det.ProductID = Inserted.ProductID)
Where tblProducts.ProductID=tblInventory_Det.ProductID

END

[/CODE]


azim

nr
SQLTeam MVY

12543 Posts

Posted - 2005-02-14 : 06:08:35
just

UPDATE tblProducts
SET Balance = tblProducts.Balance + Inserted.InQuantity
FROM tblProducts
join inserted
on tblProducts.ProductID=Inserted.ProductID

That trigger should probably be for insert only as it doesn't reverse for deletes and doesn't deal with the old amount for updates.
==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -