473,408 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Summing columns in two separate queries

I have two queries each of which having a column that I want to sum,
and then add the two sums together. When I sum one query or the
other, I get reasonable numbers. But when I try to add the two sums
together I'm getting a ridiculously high number.

Below is my SQL line that is trying to add together the colomns of
qryDetlPALIncome and qryDetlPALIncomeNoInvoice.

SELECT Sum(qryDetlPALIncomeNoInvoice.DepositAmt)+Sum(qryD etlPALIncome.Amount)
FROM qryDetlPALIncome, qryDetlPALIncomeNoInvoice;

Thanks,
Rich
Nov 13 '05 #1
3 1985
"Richard Coutts" <rc*****@comcast.net> wrote in message
news:70**************************@posting.google.c om...
I have two queries each of which having a column that I want to sum,
and then add the two sums together. When I sum one query or the
other, I get reasonable numbers. But when I try to add the two sums
together I'm getting a ridiculously high number.

Below is my SQL line that is trying to add together the colomns of
qryDetlPALIncome and qryDetlPALIncomeNoInvoice.

SELECT Sum(qryDetlPALIncomeNoInvoice.DepositAmt)+Sum(qryD etlPALIncome.Amount) FROM qryDetlPALIncome, qryDetlPALIncomeNoInvoice;


Post your table structures with some sample data and the output you need and
someone will be able to help.
Nov 13 '05 #2
>> SELECT
Sum(qryDetlPALIncomeNoInvoice.DepositAmt)+Sum(qryD etlPALIncome.Amount)
FROM qryDetlPALIncome, qryDetlPALIncomeNoInvoice;


Post your table structures with some sample data and the output you need and
someone will be able to help.


The tables are pretty straight forward with the two fields being
summed being of type 'Currency.' E.g., if
qryDetlPALIncomeNoInvoice.DepositAmt has the values
100.00
200.00
and qryDetlPALIncome.Amount has the values
25.00
35.00
50.00
then
SELECT Sum(qryDetlPALIncomeNoInvoice.DepositAmt)
FROM qryDetlPALIncomeNoInvoice;
returns 300.00 and
SELECT Sum(qryDetlPALIncome.Amount)
FROM qryDetlPALIncome;
returns 110.00 but
SELECT Sum(qryDetlPALIncomeNoInvoice.DepositAmt)+Sum(qryD etlPALIncome.Amount)
FROM qryDetlPALIncome, qryDetlPALIncomeNoInvoice;
returns 1120.00. I'm still a newbie and I'm sure I'm missing
something simple. I could break out the two sums as separate saved
queries and then sum their results together, but I'd rather not if
possible.

Thanks,
Rich
Nov 13 '05 #3
"Richard Coutts" <rc*****@comcast.net> wrote in message
news:70**************************@posting.google.c om...
SELECT Sum(qryDetlPALIncomeNoInvoice.DepositAmt)
FROM qryDetlPALIncomeNoInvoice;
returns 300.00 and
SELECT Sum(qryDetlPALIncome.Amount)
FROM qryDetlPALIncome;
returns 110.00 but
SELECT Sum(qryDetlPALIncomeNoInvoice.DepositAmt)+Sum(qryD etlPALIncome.Amount) FROM qryDetlPALIncome, qryDetlPALIncomeNoInvoice;

You have what is known as a cartesian product; your result being the sum of
all combinations of rows in the two queries.
Try this instead:

select sum(Amount) +
(
select sum(DepositAmt)
from qryDetlPALIncomeNoInvoice
)
from qryDetlPALIncome


Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Yaroslav Bulatov | last post by:
I made an array of 10 million floats timed how long it takes to sum the elements, here's what I got (millis): gcc -O2: 21 Python with numarray: 104 Python with Numeric: 302...
3
by: Edward | last post by:
ACCESS 2k I need to design a report based on a rota system for staff at various shops. The data is effectively stored in a single table, along the lines of: Initials (e.g. BH, FG, RM etc.)...
13
by: Don Sealer | last post by:
I have about 40 different defects I'm tracking. I'd like to have all of these defects totaled individually, both by month and by year. I'd like to show these results in a report. I know I could...
3
by: LurfysMa | last post by:
I would like to hear opinions on the tradeoffs of putting the tables, forms, and queries for several related datasets in separate databases vs one combined database. I am working on an...
9
by: serge | last post by:
/* Subject: How to build a procedure that returns different numbers of columns as a result based on a parameter. You can copy/paste this whole post in SQL Query Analyzer or Management Studio...
4
by: dancole42 | last post by:
So I have an invoicing database based on two main forms: Orders and OrderLines. Orders has fields like: OrderID BillingMethod OrderDate CreditCard CCExp OrdSubTotal ShippingCharge
2
by: db2admin | last post by:
Hello, What is the driving factor when making more columns indexable? Should i see if i can modify existing indexes and merge new columns in existing indexes or create a new index with new...
7
by: lethek39 | last post by:
Hey I have been trying to figure out how to sum rows and columns in a matrix square. I also have been trying to get the program to list the numbers of the diagonal in the matrix. So far this is the...
1
by: MobiusDick | last post by:
Hi Everyone, I'm having a slight problem summing (almost) an entire recordset: I have an application that when given a table of customers and their estimated annual electricity consumption will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.