Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 515
  • Last Modified:

Can I Sum and Subtract In One SQL Statement?

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
ES-Components
Asked:
ES-Components
1 Solution
 
mbizupCommented:
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
 
Vadim RappCommented:
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
 
ES-ComponentsAuthor Commented:
I did get this to work.
Thank you for your quick response.

Rick
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now