Solved

SQL 2005 Stored Procedure

Posted on 2009-07-10
3
142 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

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…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 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