Eerst moet u de datums genereren. Dan kunt u alle combinaties van datum en naam genereren. Vul tot slot de waarden in. Hier is een voorbeeld met cross apply
:
with dates as (
select @MINDATE as thedate
union all
select dateadd(day, 1, thedate)
from dates
where dateadd(day, 1, thedate) <= getdate()
)
select thedate, vals.val
from dates cross join
(select distinct name from hypothetical) h cross apply
(select top 1 val
from hypothetical h2
where h2.name = h.name and h2.date <= dates.thedate
order by date desc
) vals;