Solved

Can I Sum and Subtract In One SQL Statement?

Posted on 2013-12-10
3
449 Views
Last Modified: 2013-12-10
I am using Dreamweaver with ASP.
I have three fields where I have to sum two fields and then subtract the total from the third field. (Customer1 + Customer2) then subtract from Total Inv$

The select statement I think, would be something like this, BUT this one DOES NOT work.

SELECT SUM(Total Inv$)-(Sum(Customer1+Customer2))
WHERE Date=Date()

Any way of doing this?

Thank you...
Rick
0
Comment
Question by:ES-Components
3 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39709752
How is it not working ... wrong results or error?

Try this (use brackets around fields containing spaces or special characters).  I'm assuming all these fields are numeric:


SELECT SUM([Total Inv$])-(Sum(Customer1) + Sum(Customer2))
WHERE Date=Date()

Open in new window

0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 39709761
select field3 - (field1+field2) from mytable

This will give you the result in each row of the table. If you need the total of it all, then

select sum(field3 - (field1+field2) ) from mytable
0
 

Author Closing Comment

by:ES-Components
ID: 39709822
I did get this to work.
Thank you for your quick response.

Rick
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

920 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

14 Experts available now in Live!

Get 1:1 Help Now