Justin Darnell <> wrote:
> I'm trying to write one select statement to pull all of the data I
> need for a particular report. The first part of the statement pulls
> various things from a transactions table. It works fine. As soon as
> I add the code to access the inventory table as well, though, I end
> up with numbers that are way too large.
>
> I know I'm probably missing something obvious, but here are the
> select statements below if anyone has any insight. The first is just
> transactions table, and seemingly works. The second is the trouble
> maker.
>
> The goal is to sum all the listed transaction table fields for the
> given date, but the get the current total of inventory value,
> regardless of any date constraints on inventory.
>
> SELECT SUM(total) as Total, SUM(tax) as Tax, SUM(subtotal) as
> Subtotal, SUM(cost) as COGS, (SUM(total) -
> SUM(ext_cost))/SUM(total)*100 as GP FROM trx where trx.date =
> CTOD('09/30/06')
>
> SELECT SUM(total) as Total, SUM(tax) as Tax, SUM(subtotal) as
> Subtotal, SUM(cost) as COGS, (SUM(total) -
> SUM(ext_cost))/SUM(total)*100 as GP,
> SUM(inventory.onhand*inventory.avg_cost) FROM trx, inventory where
> trx.date = CTOD('09/30/06')
You are combining tables in the second one, trx and inventory. I'd do the
two separate tables and then combine them for your report instead.
Stephen Russell
DBA / .Net Developer
Memphis TN 38115
901.246-0159
"A good way to judge people is by observing how they treat those who
can do them absolutely no good." ---Unknown
http://spaces.msn.com/members/srussell/
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.441 / Virus Database: 268.18.3/699 - Release Date: 2/23/2007
1:26 PM
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.