select ProductID, StandardCost from Production.ProductCostHistory
inner join ProductId on Production.ProductCostHistory.p = ProductID.p
join ( select p.ProductID, max(StartDate) as StartDate from Production.ProductCostHistory
where (EndDate is NULL or EndDate > getdate()) group by ProductID ) t on t.ProductID = p.ProductID
and t.StartDate = p.StartDate
order by p.ProductID
inner join ProductId on Production.ProductCostHistory.p = ProductID.p
join ( select p.ProductID, max(StartDate) as StartDate from Production.ProductCostHistory
where (EndDate is NULL or EndDate > getdate()) group by ProductID ) t on t.ProductID = p.ProductID
and t.StartDate = p.StartDate
order by p.ProductID