34,576
社区成员
发帖
与我相关
我的任务
分享
select id= identity(int,1,1),* into # from a
update # set bb=20 where id=X
update # set dd=20*10 where id=X+1
declare curupdate cursor static for
select id from A
fetch next from curupdate into @id
open curupdate
select @bb = isnull(bb,0) from A where id = (select max(id) as id from A where id < @id)
update A set dd = @bb*10 where id = @id
fetch next from curupdate into @id
close curupdate
deallocate curupdate
declare @tb table (id int identity(1,1),num1 int,num2 int)
insert into @tb(num1) select 1
insert into @tb(num1) select 2
insert into @tb(num1) select 5
insert into @tb(num1) select 7
update t set num2=(select sum(num1) from @tb where id<=t.id) from @tb t
select * from @tb