`
studentGuy1
  • 浏览: 15443 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Sqlserver2005 游标 随机数 查询

 
阅读更多

使用SqlServer2005 随机数产生模拟数据 更新表

declare @gs int,@ge int
set @gs = -15
set @ge = -1


declare @id varchar(20)

declare cr_cursor cursor --1.定义游标

for select id from tabData where dt between '2013-11-18 12:00:00' and '2013-11-18 15:00:00'

open cr_cursor --2.打开游标

fetch From cr_cursor into @id --3.提取游标

while @@fetch_status=0

begin
update tabData set gs = cast(ceiling(rand() * (@ge - @gs) + @gs) as int) where id = @id

fetch next From cr_cursor into @id

end;

close cr_cursor --4.关闭游标

deallocate cr_cursor --5.释放游标

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics