The purpose of this request is to return products and their prices for products on sale, and the price should be from the closest date, but not equal to the date accepted mainly at the latest available price. There are no price records for each day. Something seems wrong in that the where clause contains an aggregate select statement. Is there a better way to do this? Maybe in the criteria for accession?
select
p.ProductName,
pp.Price,
pp.Date,
from product p
inner join productprice pp on p.productid = pp.productid
where
pp.evaluationdate = (select max(Date) from productprice
where productid = p.productid
and date < @DateIn)
and p.producttype = 'OnSale'
The actual query is a little more complicated, but this is essentially the problem. Thanks for your input.
EDIT
More than one product will be returned.
@Remus Rusanu @km ( @Remus Rusanu ) , , , . , - , - , , .., - . .