I have the following SELECT statement:
SELECT TOP 1 tblSalesHistory.[Product Code], tblSalesHistory.Month, tblSalesHistory.AvgSalesPrice
FROM tblSalesHistory
WHERE (((tblSalesHistory.[Product Code])="t0371") AND ((tblSalesHistory.Month)<=[Test Month]))
ORDER BY tblSalesHistory.Month DESC;
The statement works perfectly when I'm looking for only one product code, but when I want to return all product codes in the table it only returns the products that have a date matching the "Test Month". The table has a listing of product codes with the month and average sales price, but not all products are listed each month. I'm trying to find a listing of the the most current sales price for EVERY product as of a certain date ("Test Month"). The only way a product would not appear on the is if it doesn't have a sales price listed for a month prior to the "Test Month". I would like the output to include the product code, the sales price and the month applicable to the sales price. I've tried DLOOKUP and DMAX but to no avail. I've posted this question on several other sites with no response, but I believe the gurus on this site will have an answer.
Thanks in advance.
SELECT TOP 1 tblSalesHistory.[Product Code], tblSalesHistory.Month, tblSalesHistory.AvgSalesPrice
FROM tblSalesHistory
WHERE (((tblSalesHistory.[Product Code])="t0371") AND ((tblSalesHistory.Month)<=[Test Month]))
ORDER BY tblSalesHistory.Month DESC;
The statement works perfectly when I'm looking for only one product code, but when I want to return all product codes in the table it only returns the products that have a date matching the "Test Month". The table has a listing of product codes with the month and average sales price, but not all products are listed each month. I'm trying to find a listing of the the most current sales price for EVERY product as of a certain date ("Test Month"). The only way a product would not appear on the is if it doesn't have a sales price listed for a month prior to the "Test Month". I would like the output to include the product code, the sales price and the month applicable to the sales price. I've tried DLOOKUP and DMAX but to no avail. I've posted this question on several other sites with no response, but I believe the gurus on this site will have an answer.
Thanks in advance.