K
Kelii
Hi all,
This is a strange one that doesn't seem to want to work for me.
I have a table with sales data, showing sale date, item sold, and
quantity sold. I have another table with price information (i.e., item,
price effective date, and price); each item can have multiple records
in the price table depending on whether the price has been updated
(e.g., if widget a goes from a price of $1.00 to $2.00 on 1/2/2006).
I want to be able to match the correct price to each of the dates where
an item is sold. So for example:
Sales data:
Date #
Sold Item Sold
1/1/2006 WidgetA 1
1/2/2006 WidgetA 2
1/3/2006 WidgetA 3
Price data:
Price
Item Effective Price
WidgetA 1/1/2006 $1.00
WidgetA 1/2/2006 $2.00
Desire query results
Date #
Sold Item Sold Price
1/1/2006 WidgetA 1 $1.00
1/2/2006 WidgetA 2 $2.00
1/3/2006 WidgetA 3 $2.00
I've tried using simple subqueries to match the right dates, using date
criteria and the max function but nothing seems to work properly. See
below for the current SQL which results in multiple records as soon as
a new price become effective (i.e., two records, rather than 1 for all
sales occuring on and subsequent to the price change date, including
one record with the new price and one record with the old price).
Current SQL (note that I've left out much of the minutae from my
description above):
SELECT tblSalesMaster.Sale_Date, tblMenuPrice.Menu_Item_Price,
Max(tblMenuPrice.Menu_Price_Date) AS MaxOfMenu_Price_Date
FROM (tblMenuMaster INNER JOIN tblMenuPrice ON
tblMenuMaster.Menu_Description_ID = tblMenuPrice.Menu_Description_ID)
INNER JOIN (tblSalesMaster INNER JOIN tblSalesDetails ON
tblSalesMaster.Sales_ID = tblSalesDetails.Sales_ID) ON
tblMenuMaster.Menu_Description_ID = tblSalesDetails.Menu_Description_ID
WHERE (((tblSalesDetails.Menu_Description_ID)="369 TOURNADOS"))
GROUP BY tblSalesMaster.Sale_Date, tblMenuPrice.Menu_Item_Price
HAVING (((Max(tblMenuPrice.Menu_Price_Date))<=[Sale_Date]));
I'm not asking anyone to disect my query, but thoughts or tips to get
me nudged forward would be extremely helpful.
Best, (and thanks in advance)
Kelii
This is a strange one that doesn't seem to want to work for me.
I have a table with sales data, showing sale date, item sold, and
quantity sold. I have another table with price information (i.e., item,
price effective date, and price); each item can have multiple records
in the price table depending on whether the price has been updated
(e.g., if widget a goes from a price of $1.00 to $2.00 on 1/2/2006).
I want to be able to match the correct price to each of the dates where
an item is sold. So for example:
Sales data:
Date #
Sold Item Sold
1/1/2006 WidgetA 1
1/2/2006 WidgetA 2
1/3/2006 WidgetA 3
Price data:
Price
Item Effective Price
WidgetA 1/1/2006 $1.00
WidgetA 1/2/2006 $2.00
Desire query results
Date #
Sold Item Sold Price
1/1/2006 WidgetA 1 $1.00
1/2/2006 WidgetA 2 $2.00
1/3/2006 WidgetA 3 $2.00
I've tried using simple subqueries to match the right dates, using date
criteria and the max function but nothing seems to work properly. See
below for the current SQL which results in multiple records as soon as
a new price become effective (i.e., two records, rather than 1 for all
sales occuring on and subsequent to the price change date, including
one record with the new price and one record with the old price).
Current SQL (note that I've left out much of the minutae from my
description above):
SELECT tblSalesMaster.Sale_Date, tblMenuPrice.Menu_Item_Price,
Max(tblMenuPrice.Menu_Price_Date) AS MaxOfMenu_Price_Date
FROM (tblMenuMaster INNER JOIN tblMenuPrice ON
tblMenuMaster.Menu_Description_ID = tblMenuPrice.Menu_Description_ID)
INNER JOIN (tblSalesMaster INNER JOIN tblSalesDetails ON
tblSalesMaster.Sales_ID = tblSalesDetails.Sales_ID) ON
tblMenuMaster.Menu_Description_ID = tblSalesDetails.Menu_Description_ID
WHERE (((tblSalesDetails.Menu_Description_ID)="369 TOURNADOS"))
GROUP BY tblSalesMaster.Sale_Date, tblMenuPrice.Menu_Item_Price
HAVING (((Max(tblMenuPrice.Menu_Price_Date))<=[Sale_Date]));
I'm not asking anyone to disect my query, but thoughts or tips to get
me nudged forward would be extremely helpful.
Best, (and thanks in advance)
Kelii