create table #amount (
amountid int,
[date] datetime,
amount int
)
create table #period (
periodid int,
[date] datetime
)
delete from #amount
delete from #period
insert into #amount
values (1, {d '2011-01-01'}, 100),
(2, {d '2011-01-02'}, 50),
(3, {d '2011-01-04'}, 200),
(4, {d '2011-01-10'}, 20),
(5, {d '2011-01-11'}, 5)
insert into #period
values (1, {d '2011-01-01'}),
(2, {d '2011-01-03'}),
(3, {d '2011-01-05'})
select p.date, SUM(a.amount) as amount
from #period p inner join
(
select a.amountid, MAX(p.periodid) as periodid
from #amount a inner join
#period p on a.date >= p.date
group by a.amountid
) mp on p.periodid = mp.periodid inner join
#amount a on mp.amountid = a.amountid
group by p.date
Конечно, было бы проще, если бы у вашей таблицы периодов была конечная дата.