Solved

SQL store procedure problem

Posted on 2009-05-15
2
161 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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Where on a calculated field 1 29
RAISERROR WITH NOWAIT 2 24
How to create XML in below format from SQL Query in SQL Server? 3 43
How come this XML node is not read? 3 25
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Backup & Restore 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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

679 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