Pertama, Anda perlu membuat tanggal. Kemudian Anda dapat menghasilkan semua kombinasi tanggal dan nama. Terakhir, isi nilainya. Berikut adalah contoh menggunakan 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;