Nejprve musíte vygenerovat data. Poté můžete vygenerovat všechny kombinace data a jména. Nakonec doplňte hodnoty. Zde je příklad použití 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;