Well, that was going to be the new report option in your other question - to get by quarter hour any dates between start and end and that way you can graph them / matrix them any way you want...
For degree days, we are already get avgoat, and unsure what the MAX of that would be as you have written above (other than choosing the maximum value of either the calc, or zero)...
So, was adding in :
, case when avg(isnull(r1.oat,000.0)) > 15.5 then avg(isnull(r1.oat,000.0))-15.5 else 0.0 end as DailyDegrees
Then realised for the quarter hour report, it is still "daily" degrees not qurter hour degrees, and so can do the same lookup for a day as we need for the year report :
, (select sum(dd)
from (select case when avg(isnull(r2.oat,000.0)) > 15.5
then avg(isnull(r2.oat,000.0))-15.5
else 0.0 end as DD
from #reportdata r2
where convert(char(8),r2.timestamp,112) between convert(char(8),psdate,112) and convert(char(8),pedate,112)
group by convert(char(8),r2.timestamp,112)) dr2) as dailydegrees
which is added as a new column down the bottom before the :
...
FROM Periods
LEFT OUTER JOIN #ReportData r1 on r1.timestamp between psdate and pedate
...
And we can discuss the date range business in that other thread if OK with you ?