富贵资源网 Design By www.hznty.com

  以下事例,使用游标循环表#temptable中数据,然后让当前行和上一行中的argument1 相加 存放到当前行的 argument2 中,比较简单。

--drop table #temptable
create table #temptable
(
  argument1 int,
  argument2 int,
  argument3 datetime
)

declare @rowcount int,@argument1 int,@argument2 nvarchar(50),@argument3 datetime
set @rowcount=1
set @argument1=1
set @argument2=0
set @argument3=GETDATE()

while(@rowcount<100)
begin
  insert into #temptable(argument1,argument2,argument3)
        values(@argument1,@argument2,@argument3)
  
  set @argument1=@argument1 + datepart(day,@argument3)
  set @argument3=@argument3-1  
  set @rowcount = @rowcount + 1
end

--select * from #temptable

declare @lastargument2 int
set @lastargument2=0
set @argument2=0
declare _cursor cursor for(select argument1 from #temptable)
open _cursor;
fetch next from _cursor into @argument2 
while @@fetch_status = 0
begin      
  update #temptable
  set argument2=@argument2+@lastargument2
  where current of _cursor
  
  set @lastargument2=@argument2  
  fetch next from _cursor into @argument2 
end
close _cursor
deallocate _cursor

--select * from #temptable

问一个问题:

第一句fetch next from _cursor into @argument2 这句为什么不能放在while循环的第一行,删除第二行呢?我记得自己当时在这里出错了,呵呵。

富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。