Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old November 13th, 2005, 02:30 AM
Richard Coutts
Guest
 
Posts: n/a
Default 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
  #2  
Old November 13th, 2005, 02:30 AM
John Winterbottom
Guest
 
Posts: n/a
Default Re: Summing columns in two separate queries

"Richard Coutts" <rcoutts@comcast.net> wrote in message
news:70402f6b.0408010646.3132dd09@posting.google.c om...[color=blue]
> 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[/color]
Sum(qryDetlPALIncomeNoInvoice.DepositAmt)+Sum(qryD etlPALIncome.Amount)[color=blue]
> FROM qryDetlPALIncome, qryDetlPALIncomeNoInvoice;
>[/color]

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


  #3  
Old November 13th, 2005, 02:31 AM
Richard Coutts
Guest
 
Posts: n/a
Default Re: Summing columns in two separate queries

>> SELECT[color=blue][color=green]
>> Sum(qryDetlPALIncomeNoInvoice.DepositAmt)+Sum(qryD etlPALIncome.Amount)
>> FROM qryDetlPALIncome, qryDetlPALIncomeNoInvoice;[/color]
>
> Post your table structures with some sample data and the output you need and
> someone will be able to help.[/color]

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
  #4  
Old November 13th, 2005, 02:31 AM
John Winterbottom
Guest
 
Posts: n/a
Default Re: Summing columns in two separate queries

"Richard Coutts" <rcoutts@comcast.net> wrote in message
news:70402f6b.0408011804.448d53f7@posting.google.c om...[color=blue]
> SELECT Sum(qryDetlPALIncomeNoInvoice.DepositAmt)
> FROM qryDetlPALIncomeNoInvoice;
> returns 300.00 and
> SELECT Sum(qryDetlPALIncome.Amount)
> FROM qryDetlPALIncome;
> returns 110.00 but
> SELECT[/color]
Sum(qryDetlPALIncomeNoInvoice.DepositAmt)+Sum(qryD etlPALIncome.Amount)[color=blue]
> FROM qryDetlPALIncome, qryDetlPALIncomeNoInvoice;[/color]


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




 

Bookmarks

Thread Tools

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles