Sqlserver2005 游标 随机数 查询

来源:互联网 发布:淘宝企业店铺怎么提现 编辑:程序博客网 时间:2024/05/17 03:42

使用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:00'open cr_cursor --2.打开游标fetch From cr_cursor into @id --3.提取游标while @@fetch_status=0beginupdate tabData set gs = cast(ceiling(rand() * (@ge - @gs) + @gs) as int) where id = @idfetch next From cr_cursor into @idend;close cr_cursor --4.关闭游标deallocate cr_cursor --5.释放游标

原创粉丝点击