Calculating the Difference in a Query

  • Thread starter pushrodengine via AccessMonster.com
  • Start date
P

pushrodengine via AccessMonster.com

I need to calculate the difference between two fields in a query. The query
is called “qryRemote†and within the query are the fields “10-8Time†and “10-
97Timeâ€. The data entered into these fields are in the format “0000†through
to “2400â€. I need to subtract the “10-8Time from the “10-97Time†and then sum
the results and display the result in a report.

For example, after the query is run the results are:

10-8Time 10-97Time
---------------------------------
1307 1331
1858 1909
2018 2023

First the difference is determined: 10-8Time is subtracted form the 10-97Time
for each.

10-97Time 10-8Time
--------------------------------
1331 - 1307 = 24
1909 - 1858 = 51
2023 - 2018 = 5

Then the differences are added.

24+51+5 = 80

The number 80 is displayed as a number within a report as the Total Time in
Seconds.

Thanks
 
J

John Spencer

From the little you have given us you seem to want a query like

SELECT SUM([10-97Time]-[10-8Time]) as TotalTime
FROM [YourTable]

Or you can use an expression for a control's control source in a report.

=DSUM("[10-97Time]-[10-8Time]","[YourTable]")

Or if the total time is to be displayed in a control in a group footer or
report footer
=SUM([10-97Time]-[10-8Time])

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
P

pushrodengine via AccessMonster.com

The important thing I need is the difference (subtraction) of the query
results for "10-97Time" and "10-8Time.

Subtract the "10-97Time" form the "10-8Time" equals the difference of the two
numbers.

Can this be done in a query?


John said:
From the little you have given us you seem to want a query like

SELECT SUM([10-97Time]-[10-8Time]) as TotalTime
FROM [YourTable]

Or you can use an expression for a control's control source in a report.

=DSUM("[10-97Time]-[10-8Time]","[YourTable]")

Or if the total time is to be displayed in a control in a group footer or
report footer
=SUM([10-97Time]-[10-8Time])
I need to calculate the difference between two fields in a query. The query
is called "qryRemote" and within the query are the fields "10-8Time" and
[quoted text clipped - 32 lines]
 
J

John Spencer

IF you have two fields that are number fields (or two columns, if you
prefer) with those names, all you need to do is enter the following in the
query grid.

Field: TheDifference: [10-97Time]-[10-8Time]

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..

pushrodengine via AccessMonster.com said:
The important thing I need is the difference (subtraction) of the query
results for "10-97Time" and "10-8Time.

Subtract the "10-97Time" form the "10-8Time" equals the difference of the
two
numbers.

Can this be done in a query?


John said:
From the little you have given us you seem to want a query like

SELECT SUM([10-97Time]-[10-8Time]) as TotalTime
FROM [YourTable]

Or you can use an expression for a control's control source in a report.

=DSUM("[10-97Time]-[10-8Time]","[YourTable]")

Or if the total time is to be displayed in a control in a group footer or
report footer
=SUM([10-97Time]-[10-8Time])
I need to calculate the difference between two fields in a query. The
query
is called "qryRemote" and within the query are the fields "10-8Time" and
[quoted text clipped - 32 lines]
 
P

pushrodengine via AccessMonster.com

Thank you very much John. Works Great!

John said:
IF you have two fields that are number fields (or two columns, if you
prefer) with those names, all you need to do is enter the following in the
query grid.

Field: TheDifference: [10-97Time]-[10-8Time]
The important thing I need is the difference (subtraction) of the query
results for "10-97Time" and "10-8Time.
[quoted text clipped - 24 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top