sql2000语句如何循环执行

有如下数据表#tmp7,
fint fkmid fqcye fdebit fcredit fye
1 2 100 100
2 2 10
3 2 20
.... ...
想实现如下效果,从第二行起每一行的fqcye等于上一行的fye,
同时fye=fqcye+fdebit-fcredit
我写了如下语句
update a
set a.fqcye=b.fye
from #tmp7 a ,#tmp7 b
where a.fint=b.fint+1 and a.fkmid=b.fkmid
update #tmp7
set fye=fqcye+fdebit-fcredit
但需执行多次才能完成,请问有什么方法可以让语句循环执行之最后一行
最好有具体语句
最终想实现的效果如下
fint fkmid fqcye fdebit fcredit fye
1 2 100 100
2 2 100 10 110
3 2 110 20 90
如此循环至最后一行记录

已自行解决了,谢谢大家!

第1个回答  2010-12-16
while 1
update #tmp7
set fye=fqcye+fdebit-fcredit
第2个回答  2010-12-17
declare @i int
declare @j int
declare @m int
declare @n int
set @i=0
set @j=0
update @tmp7 set fqcye=@i,fye=@i+@j,@i=@i+@j,@j=fqcye+fdebit-fcredit
只是第一条记录的fqcye 变成了0,因为没有上一条记录的fye