加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

Sqlserver2005 游标 随机数 查询

发布时间:2020-12-12 13:41:20 所属栏目:MsSql教程 来源:网络整理
导读:使用SqlServer2005 随机数产生模拟数据 更新表 declare @gs int,@ge intset @gs = -15set @ge = -1declare @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

使用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.释放游标

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读