Solved

SQL 2005 Stored Procedure

Posted on 2009-07-10
3
140 Views
Last Modified: 2012-05-07
I have a SP that Picks Sales O)rder lines and updates the stock with Qty Picked.

If the user picks more than the available stock it then goes negative. Is there an eay way to just set StockQty to zero?
If @PickType = 'PickMan' 
	Begin
		Update OrderDetail Set QtyPicked = @PickQty, Pickedby = @pUser, DatePicked = GETDATE ( )
		Where OrderNo = @OrderNo and Barcode = @Bcode
		set @iMsg = 'Picked ordered qty for ' + @Bcode
 
		-- update the stock qty
		Update Stock Set StockQty = StockQty - isnull((@PickQty),0), 
		QtyReserved = QtyReserved - isnull((@PickQty),0)
		Where Barcode = @Bcode
		goto ShowResults
	End

Open in new window

0
Comment
Question by:HKFuey
  • 2
3 Comments
 
LVL 31

Accepted Solution

by:
RiteshShah earned 500 total points
ID: 24821454
can you do something like this?


 Update Stock Set StockQty = case when StockQty - isnull((@PickQty),0)<0 then 0 else StockQty - isnull((@PickQty),0) end ,
                QtyReserved = QtyReserved - isnull((@PickQty),0)
                Where Barcode = @Bcode
                goto ShowResults
0
 

Author Closing Comment

by:HKFuey
ID: 31601987
That works great, thanks!
0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24821601
>>Author Comments:
That works great, thanks!<<

welcome, glad to help!!!

Ritesh Shah

www.SQLHub.com
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question