Use a recursive query to generate the series of target dates, and
another declared table to materialize the hour range. Use these two
table to perform a left join against your target table, substituting
zeroes for the nulls, where no data existed. See example below.
with alldates(cal_dt) as (
values date('2008-01-01')
union all
select cal_dt + 1 day
from alldates
where cal_dt < '2008-01-05'
),
allhours(hour) as (
values
6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22
),
mydata(cal_dt, hour, val) as (
values
(date('2008-01-03'),7,3),
(date('2008-01-03'),8,9),
(date('2008-01-03'),20,9),
(date('2008-01-05'),8,15),
(date('2008-01-05'),12,3)
)
select alldates.cal_dt , allhours.hour, value(mydata.val,0)
from alldates
join allhours on 1=1
left join mydata on alldates.cal_dt = mydata.cal_dt and allhours.hour
= mydata.hour
order by 1,2
On Sep 26, 9:33 am, Massimiliano Campagnoli <m...@paoloastori.com>
wrote:
> Good morning,
>
[quoted text clipped - 54 lines]
>
> Thanks.
Massimiliano Campagnoli - 27 Sep 2008 15:22 GMT
> Use a recursive query to generate the series of target dates, and
> another declared table to materialize the hour range. Use these two
[quoted text clipped - 90 lines]
>
> > Thanks.
Thanks, I got it.