Christineeve
Programmer
Hello,
(I have inherited this database. Things are not done properly. I'm tasked with "makeing it work." I redesign whenever there is a chance to fix it.)
I have a query that I'm trying to remove the parameter prompt asking for a date (six times). The designer of this database is, his wisdom, created this query based on at least six other queries. The date prompt occurs at nearly every query.
I need to change this parameter prompt to reference a start and end date on a form. Pulling the date from the form is sort of working*. But the dollar amount being returned is wrong. As follows:
Original Query
**Fields removed to make it shorter.
Desired Result for SumOfAmount:
TradeDate StoreName SumOfAmount
09-Sep-08 Store #9848 66,005,000.00
New Query:
Result (Incorrect SumofAmount)
**Several fields removed to keep it shorter.
TradeDate StoreName SumOfAmount
09-Sep-08 Store #9848 2,690,000.00
When I backtrack through the queries used to obtain this result, the SumOfAmount IS 2,690,000.00. So I cannot figure out how the heck it becomes 66,005,000.00!!
How could the "Having" clause in my SQL statement make such a big deal? I realize that Having is necessary when you're working with Group by queries. I'm stumped.
Your advice would be appreciated.
(I have inherited this database. Things are not done properly. I'm tasked with "makeing it work." I redesign whenever there is a chance to fix it.)
I have a query that I'm trying to remove the parameter prompt asking for a date (six times). The designer of this database is, his wisdom, created this query based on at least six other queries. The date prompt occurs at nearly every query.
I need to change this parameter prompt to reference a start and end date on a form. Pulling the date from the form is sort of working*. But the dollar amount being returned is wrong. As follows:
Original Query
Code:
SELECT
[COLOR=blue][Fo Date] AS PurchaseDate, *The Parameter to remove. [/color blue]
FoRecords.StoreName,
FoRecords.Plan,
FoRecords.[A/C#],
BarLimits.SeqNum,
BarLimits.Limit,
BarLimits.[Exp Date],
BarLimits.[W/T],
BarLimits.[Index #],
FoRecords.Center,
FoRecords.Acct,
Sum(FoRecords.Amount) AS SumOfAmount,
FoRecords.RateType, FoRecords.[Purch&Sold]
FROM
BarLimits INNER JOIN FoRecords ON (BarLimits.StoreName = FoRecords.StoreName) AND
(BarLimits.[Purch&Sold] = FoRecords.[Purch&Sold])
GROUP BY
[Fo Date], FoRecords.StoreName,
FoRecords.Plan,
FoRecords.[A/C#],
BarLimits.SeqNum,
BarLimits.Limit,
BarLimits.[Exp Date],
BarLimits.[W/T],
BarLimits.[Index #],
FoRecords.Center,
FoRecords.Acct,
FoRecords.RateType,
FoRecords.[Purch&Sold];
**Fields removed to make it shorter.
Desired Result for SumOfAmount:
TradeDate StoreName SumOfAmount
09-Sep-08 Store #9848 66,005,000.00
New Query:
Code:
SELECT
FoRecords.PurchaseDate,
FoRecords.StoreName,
FoRecords.Plan,
FoRecords.[A/C#],
BarLimits.SeqNum,
BarLimits.Limit,
BarLimits.[Exp Date],
BarLimits.[W/T],
BarLimits.[Index #],
FoRecords.Center,
FoRecords.Acct,
Sum(FoRecords.Amount) AS SumOfAmount,
FoRecords.RateType,
FoRecords.[Purch&Sold]
FROM BarLimits INNER JOIN FoRecords ON (BarLimits.StoreName = FoRecords.StoreName) AND
(BarLimits.[Purch&Sold] = FoRecords.[Purch&Sold])
GROUP BY
FoRecords.PurchaseDate,
FoRecords.StoreName,
FoRecords.Plan,
FoRecords.[A/C#],
BarLimits.SeqNum,
BarLimits.Limit,
BarLimits.[Exp Date],
BarLimits.[W/T],
BarLimits.[Index #],
FoRecords.Center,
FoRecords.Acct,
FoRecords.RateType,
FoRecords.[Purch&Sold]
[COLOR=blue]
HAVING (((FoRecords.PurchaseDate)=#9/9/2008#));
[/color blue]
Result (Incorrect SumofAmount)
**Several fields removed to keep it shorter.
TradeDate StoreName SumOfAmount
09-Sep-08 Store #9848 2,690,000.00
When I backtrack through the queries used to obtain this result, the SumOfAmount IS 2,690,000.00. So I cannot figure out how the heck it becomes 66,005,000.00!!
How could the "Having" clause in my SQL statement make such a big deal? I realize that Having is necessary when you're working with Group by queries. I'm stumped.
Your advice would be appreciated.