Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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 June 7th, 2004, 01:23 AM
Authorized User
 
Join Date: Apr 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default updating unit_in_stock column after order

i am building a shopping cart. I want to update the UNIT_IN_STOCK column in database after order have been submitted. i want to subtract the quanity value from the order made from the UNIT_IN_STOCK column in database. how would the sql statement be like?? i tried this but it didnt work. any suggestions??

CREATE PROCEDURE update_Products_By_name
(

@ProductName varchar,
@UnitInStock int

)
AS

UPDATE Products
SET UnitInStock=(UnitInStock-@UnitInStock)
WHERE ProductName = @ProductName
GO


rrr
__________________
rrr
 
Old June 7th, 2004, 01:43 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

What is the field type of 'UnitInStock'?

Om Prakash
 
Old June 7th, 2004, 01:50 AM
Authorized User
 
Join Date: Apr 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

UnitInStock is type int

rrr
 
Old June 7th, 2004, 01:55 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

Then i think you should check for @ProductName column, the product which u are passing is same or not (I mean check for spaces in the beginning or end for product name).

Om Prakash
 
Old June 7th, 2004, 02:15 AM
Authorized User
 
Join Date: Apr 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

SET UnitInStock=(UnitInStock-@UnitInStock)

is the UnitInStock= UnitInStock - @UnitInStock a valid SQL statement??
(kinda like a = a-b in C++)

rrr
 
Old June 7th, 2004, 03:05 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

UnitInStock= UnitInStock - @UnitInStock
is a valid statement.

Another possibility could be null in UnitInStock column. If current value in UnitInStock column is null, then it will not update.



Om Prakash
 
Old June 7th, 2004, 11:11 AM
Registered User
 
Join Date: Jun 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Olambe,

I would realize such by putting a insert trigger on the order(details) table and use the inserted table available within the trigger to update the UNIT_IN_STOCK from the products table.

You can even extend the business rule you created this way by marking the trigger for update and and have it in/decrement the UNIT_IN_STOCK acoording to the difference between inserted/delete "table" once you update any order(detail).

See Books online for more info on triggers.

Regards,

Jago
 
Old June 7th, 2004, 04:33 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

you can try this as om_prakash stated
CREATE TRIGGER 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

Here I used unitsSold and left the unitsinstock for my starting Inventory. When I need to do an inventory I can evalaute and
compare units sold verses units I start with.







Similar Threads
Thread Thread Starter Forum Replies Last Post
Rearrange the column order in a datatable/dataset kiran_q8 ASP.NET 2.0 Basics 6 July 3rd, 2007 12:12 PM
Updating products quantity when order item insert Tawanda BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 June 7th, 2007 02:30 PM
Rearrange the column order in a datatable/dataset kiran_q8 ASP.NET 2.0 Professional 2 May 3rd, 2007 08:46 AM
Column Order busher ASP.NET 1.0 and 1.1 Basics 11 August 6th, 2005 12:44 PM
ORDER BY a column? gilgalbiblewheel Classic ASP Databases 1 March 30th, 2005 10:37 AM





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