Solved

SQL store procedure problem

Posted on 2009-05-15
2
160 Views
Last Modified: 2012-05-07
I have the following stored prodedure below.

I have columns called qty1, qty2, qty3, qty4 in tblZPLUSales and I want a way to add all these values on a row together and then minus this from my currentstock column in tblStock

For Example

Qty1 = 10
Qty2 = 2
Qty3 = 30
Qty4 = 11

A total: 53

Now update my tblStock taking away the 53.
UPDATE p set p.currentstock=p.currentstock-u.qty1 FROM tblStock p join tblZPLUSales u on p.id=u.id

Open in new window

0
Comment
Question by:richard_gar
2 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 24397589
UPDATE p set p.currentstock=p.currentstock- (u.qty1+ u.qty2 +u.qty3+u.qty4 )
FROM tblStock p join tblZPLUSales u on p.id=u.id
0
 

Author Closing Comment

by:richard_gar
ID: 31582005
spot on, cheers
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

860 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