SQl Server 2000 Trigger
Hi all,
i have three tables Customer, Product, Order in my database. what i am trying to do is when i enter the customer order quantity in order table, it should fire trigger and update the quantity_on_hand field in product table(e.g. if customer wanst to order product_id 1 in the amount of 5, if i have quantity_on_hand in product table is 15, after inserting customer order, the quantity_on_ hand should be 15-5=10). i tried to write following trigger, but when i execute the following code in Query analyzer, it gives me error message
CREATE TRIGGER tgInsertOrder
ON Order
FOR INSERT
AS
BEGIN
declare @product_id int
declare @order_qty int
@product_id = product_id,
@order_qty = order_qty
from inserted
update product
set quantity_on_hand = quantity_on_hand - @order_qty
where product_id = @product_id
END
GO
i get following error
Server: Msg 170, Level 15, State 1, Procedure tgInsOrder, Line 9
Line 9: Incorrect syntax near '@product_id'.
Server: Msg 137, Level 15, State 1, Procedure tgInsOrder, Line 13
Must declare the variable '@order_qty'.
any help or sample code would be greatly appreciated
|