Using innert select to replace a reversed relation

select od.OrderID,p.CategoryID , year(o.OrderDate) year, month(o.OrderDate) month,
od.UnitPrice * od.Quantity
* (select top 1 rate from ExchangeRate er 
where er.Currency = 'USD' and er.EffectiveDate <=o.OrderDate
order by er.EffectiveDate desc)
rowTotal

from [Order Details] od 
	left outer join Products p on p.ProductID = od.ProductID
	left outer join Orders o on o.OrderID = od.OrderID 

Help us improve, Edit this page on GitHub
or email us at info@fireflymigration.com