首页 > 其他 > 详细

游标处理

时间:2017-03-10 18:15:56      阅读:265      评论:0      收藏:0      [点我收藏+]

declare m_cursor cursor scroll for
select a.CreateTime,s.CommentID from Comment s inner join Article a on s.ObjectID=a.ArticleID where ArticleID=122
for update
-- 打开游标
open m_cursor
declare @dataTimes Datetime, @CommentId int
--填充数据
fetch next from m_cursor into @dataTimes,@CommentId
--假如检索到了数据,才处理
while @@FETCH_STATUS=0
begin

update Comment set CreateTime=dateadd(MINUTE,CEILING(rand()*1200),cast(@dataTimes as datetime)) where CommentId=@CommentId
--填充下一条数据
fetch next from m_cursor into @dataTimes,@CommentId
end
-- 关闭游标
close m_cursor
--释放游标
deallocate m_cursor

游标处理

原文:http://www.cnblogs.com/xujie520/p/6531676.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!