Solved

Can I Sum and Subtract In One SQL Statement?

Posted on 2013-12-10
3
437 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
Comment Utility
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
Comment Utility
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
Comment Utility
I did get this to work.
Thank you for your quick response.

Rick
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

744 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

17 Experts available now in Live!

Get 1:1 Help Now