Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL store procedure problem

Posted on 2009-05-15
2
Medium Priority
?
171 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Screencast - Getting to Know the Pipeline
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased riskā€¦

782 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