Create table a
(
a varchar(20),
b Decimal(18,2),

)Insert into aselect 'a', 1.2
union
select 'b', 3.5
Union
select 'c', 2.3select id=identity(int,1,1),* into #t from (select a,b,-b as c from a)tupdate #t
set c=abs(c)
where id%2=1
select a,c=(select abs(sum(c)) from #t where id<=a.id)
from #t aDrop table #t,a

解决方案 »

  1.   

    use csdn 
    select * from a 
    go drop table #a
    select * into #a from a where 1=2
    go declare a_cursor cursor for select * from a 
    open a_cursor
    declare @a varchar(20)
    declare @b decimal(18,2)
    declare @b_new decimal(18,2)
    fetch next from a_cursor into @a, @b while  @@fetch_status = 0 
    begin
    insert into #a values (@a, @b )
    fetch next from a_cursor into @a,@b_new
    set @b=@b_new-@b
    endclose a_cursor
    deallocate a_cursorselect * from #a 功能实现了。
    还请大家指教。