create table #t([date] datetime, IONUM int, [MONTH] int)
insert into #t select '2008-1-1', 1, 0
union all select '2008-1-11', 2,0
union all select '2008-1-21', 2,0
union all select '2008-2-1', 2,0
update #t
set [MONTH] =
case date
when '2008-01-01' Then (select sum(IONUM) from #t where [date] <= '2008-01-31' and [date] >= '2008-01-01')
when '2008-02-01' Then (select sum(IONUM) from #t where [date] <= '2008-02-29' and [date] >= '2008-02-01') end
create table #t([date] datetime, IONUM int, [MONTH] int)
insert into #t select '2008-1-1', 1, 0
union all select '2008-1-11', 2,0
union all select '2008-1-21', 2,0
union all select '2008-2-1', 2,0
update #t
set [MONTH] =
case date
when '2008-01-01' Then (select sum(IONUM) from #t where [date] <= '2008-01-31' and [date] >= '2008-01-…
[/Quote]