Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 25th, 2004, 08:36 PM
Authorized User
 
Join Date: Mar 2004
Posts: 74
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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


 
Old April 25th, 2004, 10:39 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

I have work on something similar

createTRIGGER dbo."UpdateQuantity" ON dbo.Order_Details
FOR INSERT
Not for replication
AS
UPDATE dbo.products
SET dbo.products.UnitsSold=inserted.Quantity + inserted.Quantity
FROM inserted
where dbo.products.productID=inserted.productID

Search on previous post because someone already help me with this.

 
Old April 25th, 2004, 11:12 PM
Authorized User
 
Join Date: Jun 2003
Posts: 77
Thanks: 0
Thanked 0 Times in 0 Posts
Default

everest, i think the begin and end are not required in your trigger.
 
Old April 26th, 2004, 12:10 AM
Authorized User
 
Join Date: Mar 2004
Posts: 74
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,
 evenif i deleted begin and end, it still doesn't seem to work

further help would be great

 
Old April 26th, 2004, 12:52 AM
Authorized User
 
Join Date: Mar 2004
Posts: 74
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i came accross this problem. thanks for the help
i solved the problem

 
Old April 26th, 2004, 01:44 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

what was your solution, can you post it?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Trigger Problem in sql server monika.vasvani SQL Language 1 March 1st, 2007 07:09 AM
SQL Server 2000 and SQL Server 2000 CE dparsons SQL Server 2000 1 July 31st, 2006 12:59 PM
looking for access 2000 to sql server 2000 sql/que method SQL Server 2000 0 July 7th, 2005 12:46 PM
Trigger in SQL Server 2000 deniscuba SQL Server 2000 4 April 1st, 2005 11:37 AM
SQL SERVER 2000 AND ACCESS 2000 ckentebe SQL Server 2000 3 June 17th, 2004 08:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.