Solved

SQL store procedure problem

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now