Click to See Complete Forum and Search --> : trigger for sql2005


catchup
07-10-2006, 11:57 AM
Hi i'm about to embark on my first trigger. I have an table 'Inventory' that needs two columns populated from the 'Products' table when Inventory is Created and Updated. This is what i have so far which is giving me an error of incorrect syntax 'inv'

This is what i have, thanks:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE TRIGGER Schema_Name.inventory_tgr
ON Schema_Name.Inventory
AFTER INSERT,UPDATE
AS
BEGIN
SET NOCOUNT ON;

update Inventory inv set inv.GDS = i.GDS, inv.ProdID = i.ProdId
from inserted i where inv.ProductID = i.ProductID

END
GO

aussie girl
07-10-2006, 12:05 PM
What is inv in your update statement? It shouldn't be there. It's not the correct syntax for an update statement

update Inventory inv<---??

catchup
07-10-2006, 12:42 PM
"inv" was trying to use virtual inserted table instead, like i said i very new to this.

I also get a comma error when i attempt this, any suggestions (thanks):

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE TRIGGER inv.inventory_tgr
ON Inventory.Inventory
AFTER INSERT,UPDATE
AS
BEGIN
SET NOCOUNT ON;



UPDATE Inventory.GDS, Inventory.prodID FROM Product
WHERE Inventory.ProductID = Product.ProductID
SET Inventory.GDS = Product.GDS, Inventory.prodID = Product.prodID

END
GO

aussie girl
07-11-2006, 12:04 AM
The update statement should be..

UPDATE Inventory
SET Inventory.GDS = Product.GDS, Inventory.prodID = Product.prodID
WHERE Inventory.ProductID = Product.ProductID