ITeye博客

Sqlserver2005 游标 随机数 查询

studentGuy1 · 2013-11-18 16:51 · Markdown

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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。