Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

i need to get all the sum that are <0 and the ActSum >0 only

Posted on 2006-05-03
6
Medium Priority
?
243 Views
Last Modified: 2010-04-16
this is the code in the sqlCommand :
SELECT     SUM(Actions.ActionSum) AS ActSum, Actions.CustId, COUNT(*) AS Expr2, Customers.CustRunID, Customers.CustName, Customers.CustAddres,
                      Customers.CustCity, Customers.CustPhone, Customers.CustFax, Customers.CustCell, Customers.CustRemarks
FROM         Actions INNER JOIN
                      Customers ON Actions.CustId = Customers.CustRunID
WHERE     (ActSum < 0) // not working its says that this colum ActSum is invalid
GROUP BY Actions.CustId, Customers.CustRunID, Customers.CustName, Customers.CustAddres, Customers.CustCity, Customers.CustPhone,
                      Customers.CustFax, Customers.CustCell, Customers.CustRemarks
i need to pull out only the rows that the ActSum is <=0
how can i do it ?
thanks !!!
0
Comment
Question by:Tech_Men
6 Comments
 
LVL 25

Accepted Solution

by:
dstanley9 earned 600 total points
ID: 16598062
Try


SELECT     SUM(Actions.ActionSum) AS ActSum, Actions.CustId, COUNT(*) AS Expr2, Customers.CustRunID, Customers.CustName, Customers.CustAddres,
                      Customers.CustCity, Customers.CustPhone, Customers.CustFax, Customers.CustCell, Customers.CustRemarks
FROM         Actions INNER JOIN
                      Customers ON Actions.CustId = Customers.CustRunID
WHERE     (Actions.ActionSum < 0) // not working its says that this colum ActSum is invalid
GROUP BY Actions.CustId, Customers.CustRunID, Customers.CustName, Customers.CustAddres, Customers.CustCity, Customers.CustPhone,
                      Customers.CustFax, Customers.CustCell, Customers.CustRemarks

You cannot use column aliases in WHERE clauses.
0
 

Author Comment

by:Tech_Men
ID: 16598790
the resualt isnt the true sum
its not working
0
 
LVL 44

Assisted Solution

by:Arthur_Wood
Arthur_Wood earned 400 total points
ID: 16599079
try this:

SELECT     SUM(Actions.ActionSum) AS ActSum, Actions.CustId, COUNT(*) AS Expr2, Customers.CustRunID, Customers.CustName, Customers.CustAddres,
                      Customers.CustCity, Customers.CustPhone, Customers.CustFax, Customers.CustCell, Customers.CustRemarks
FROM         Actions INNER JOIN
                      Customers ON Actions.CustId = Customers.CustRunID
GROUP BY Actions.CustId, Customers.CustRunID, Customers.CustName, Customers.CustAddres, Customers.CustCity, Customers.CustPhone,
                      Customers.CustFax, Customers.CustCell, Customers.CustRemarks
HAVING SUM(Actions.ActionSum) < 0

AW
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 10

Expert Comment

by:smegghead
ID: 16599082
You have to specify the 'where' part of the SQL in the 'having' section..

So it will appear like..

SELECT     SUM(Actions.ActionSum) AS ActSum, Actions.CustId, COUNT(*) AS Expr2, Customers.CustRunID, Customers.CustName, Customers.CustAddres,
                      Customers.CustCity, Customers.CustPhone, Customers.CustFax, Customers.CustCell, Customers.CustRemarks
FROM         Actions INNER JOIN
                      Customers ON Actions.CustId = Customers.CustRunID
GROUP BY Actions.CustId, Customers.CustRunID, Customers.CustName, Customers.CustAddres, Customers.CustCity, Customers.CustPhone,
                      Customers.CustFax, Customers.CustCell, Customers.CustRemarks
HAVING sum(Actions.ActionSum)<0

Smg
0
 
LVL 10

Expert Comment

by:smegghead
ID: 16599727
WTF ? you split the points between someone who didn't get the right answer and someone who said the same as me (albeit a minute before). Surely a point split between the two people who answered correctly would be more fair ?
0
 

Author Comment

by:Tech_Men
ID: 16620504
ohhhhhh i am so sorry :(
i didint paid attention because someone interrupt me when i did it
what can i do to make u up ?
i am terrible terrible sorry
can i do something to correct this mistake ?
please tell me how
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Loops Section Overview
Suggested Courses

810 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