Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 12th, 2007, 05:07 PM
Authorized User
 
Join Date: Sep 2003
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default Subtraction in an Access Query

Hello everyone,

I need a query where I calculate the net profit (or loss) in the given
transactions. So, I have to sum up all the positive value transactions
and subtract (actually add since the sum here will be negative) the
sum of all negative value transactions.

So, I have a table called Records_T which holds a field called Amount.

I can calculate the sum of all +ve records as follows:

SELECT Sum(Records_T.Amount) AS AMOUNT FROM Records_T WHERE
(Records_T.Amount)>0

Similarly, the negative records sum is:

SELECT Sum(Records_T.Amount) AS AMOUNT FROM Records_T WHERE
(Records_T.Amount)<0

Now, how can I combine these queries so that I get the sum of the
values returned by these two queries??

Thanks for any help you can give me. Really appreciate it.

 
Old April 13th, 2007, 04:32 AM
Registered User
 
Join Date: Apr 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Create a query via the database and insert the required table

Select the Records_T.Amount field into the query grid.

On the tool bar, click on the totals symbol (the sigma or Greek S) and check that the totals row appears in the query grid.


Select sum from the drop down list for the field "Amount" in this row.

Run the query and it will add up both the negative and positive values to give an overall sum

You can of course filter this for values greater than or less than 0 via the criteria.


Hope this helps






Michael109
 
Old April 13th, 2007, 06:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Unless you need to show the positives and the negatives separately, why even separate the two to then later add? Just simply add them ALL to start with. The negative ones will subtract out of the positive ones anyway.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division





Similar Threads
Thread Thread Starter Forum Replies Last Post
subtraction operator overload arnie6 C++ Programming 0 April 19th, 2005 07:57 AM
need access query kale_tushar Access 2 January 3rd, 2005 05:26 AM
Dates Subtraction akhamis SQL Language 1 December 2nd, 2004 04:38 PM
subtraction collie SQL Server 2000 3 November 26th, 2004 01:03 AM
Access: need a Query. please help me... alienscript Access VBA 1 December 14th, 2003 01:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.