This query is meant to retrieve a count of the no. of stocks that have prices in the last 8 days.
count(*) as PriceToday
from exchange as E left outer join pricehistory as PH
where PH.marketdate > (select CONVERT(nvarchar(30), GETDATE(), 112)-8)
group by E.exchangename,PH.marketdate
The problem is that the dates are stored in format yyyymmdd, so it's doing arithmetic calcualations not date calculations. How do I convert it to dates?