select TickerName, convert(char(8),quoteDate,112) quoteDate, min(quote), max(quote), avg(quote) from quotes where quoteDate between @startPeriod and @endPeriod group by TickerName, convert(char(8),when,112) order by TickerName, convert(char(8),when,112)