Solved

Can I Sum and Subtract In One SQL Statement?

Posted on 2013-12-10
3
460 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

831 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