declare @i numeric(28,6),@j numeric(28,6),@V numeric(28,6)
set @i=0,@j=0
select *,0 as ValueCol into #temp from 表
update #temp
set ValueCol=((字段b+@j)-(字段a+@i))/(字段b+@j)
,@I=@i字段a
,@j=@j字段b
select * from #temp
set @i=0,@j=0
select *,0 as ValueCol into #temp from 表
update #temp
set ValueCol=((字段b+@j)-(字段a+@i))/(字段b+@j)
,@I=@i字段a
,@j=@j字段b
select * from #temp
declare @i numeric(28,6),@j numeric(28,6)
set @i=0
set @j=0
select *,case(0 as numeric(28,6)) as ValueCol into #temp from 表
update #temp
set ValueCol=((字段b+@j)-(字段a+@i))/(字段b+@j)
,@I=@i字段a
,@j=@j字段b
select * from #temp
PB:利用datawindow实现起来更简单方便~
select *,cast(0 as decimal(10,2)) as v into #r from a
declare @i decimal(10,4), @j decimal(10,4)
select @i=0,@j=0update #r
set @i=@i+a,@j=@j+b,v=(@j-@i)/ @j
as
declare @aa int,@bb int
declare @sumab int,@addb int
declare @diva real
set @sumab=0
set @addb=0
declare a cursor for select a,b from addab
open a
fetch next from a into @aa,@bb
while @@fetch_status=0
begin
set @sumab=@sumab+@aa
set @addb=@addb+@bb
set @diva=(@addb-@sumab)/@addb
fetch next from a into @aa,@bb
end close a
deallocate a