这就是您接受尼克斯建议和实施的方式:
--This just replicates your load to a staging table
declare @t table (Col1 int,StartDate date,EndDate date,Col4 money)
insert into @t
values
(1234,'10/7/2018','10/28/2018',1.000)
--This will be your insert into final
select Col1,EndDate as [Date],Col4
from @t
union all
select t.Col1,a.Date,t.col4
from @t t
cross apply (select *
from dDate
where [Date] >= t.StartDate --This includes start date
and [Date] < t.EndDate --This does not include ED, I did this to avoid result not ending on same day of the week
and [WeekDay] = datepart(dw,t.StartDate) --Weekly records starting on SD and progressing weekly
)a
order by 1,2 -- Just for your viewing pleasure
结果:
Col1 Date Col4
1234 2018-10-07 1.00
1234 2018-10-14 1.00
1234 2018-10-21 1.00
1234 2018-10-28 1.00
这假设您有一个 DateDimension 或“日历表”,其中包含字段 Date(表示日历日期)和 Weekday(表示星期几的数值)。