If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > sql query to substract to columns

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-23-05, 17:50
obulldog27 obulldog27 is offline
Registered User
 
Join Date: Aug 2004
Posts: 5
sql query to substract to columns

I have the following sql statement in Data environment that currently gives me this report. I am using vb6sp6 and access 2002 db.
Quote:
HTML Code:
SPACENO| NAME |TOTALDUE| CHECKAMT| DIFFERENCE
10        Joe        300       100            200
20        Mary       300      300              0
30        Dave       300             
40        Tom        300      300              0
                                          total =  200
Quote:
basically, total due - checkamt will equal diff., if there are duplicate spaceno
then the two checkamt will add up and only show one spaceno. The the total of all diff is calculated at the end of the report. I dont need any sql for the total.
Code:
SELECT gas_bill.spaceno, max(gas_bill.name_gas) as name_gas, Max(gas_bill.total_due) as total_due, Sum(receipts.check_amt) as check_amt,
(Max(gas_bill.total_due) -Sum(receipts.check_amt)) as diffl
FROM receipts RIGHT JOIN gas_bill ON receipts.spaceno=gas_bill.spaceno group by gas_bill.spaceno
Quote:
I need to add another column called cashamt to do the same as check amt to have the same function and using the same diff column to show the results.
Quote:
HTML Code:
SPACENO| NAME |TOTALDUE| CHECKAMT| CASHAMT | DIFF 
10        Joe     300       100           200
20        Mary   300       300           0
30        Dave   300            
40        Tom    300       300           0
50        AL      300                300  0
                                                    total =  200

Last edited by obulldog27; 09-23-05 at 18:04.
Reply With Quote
  #2 (permalink)  
Old 10-01-05, 15:45
Peter.Vanroose Peter.Vanroose is offline
Registered User
 
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
Could it be that you need to change "MAX(total_due)" to "SUM(total_due)" (twice) in
Code:
SELECT gas_bill.spaceno, max(gas_bill.name_gas) as name_gas, MAX(gas_bill.total_due) as total_due, Sum(receipts.check_amt) as check_amt,
(MAX(gas_bill.total_due) -Sum(receipts.check_amt)) as diffl
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On