CREATEPROCEDURE[dbo].[pro_CURSOR] AS BEGIN --声明一个游标 DECLARE MyCURSOR CURSORFOR SELECT userid,depid FROM users --打开游标 open MyCURSOR --声明两个变量 declare@useridvarchar(50) declare@depidvarchar(50) --循环移动 fetchnextfrom MyCURSOR into@userid,@depid (取第一行数据) while(@@fetch_status=0) begin update users set description=(select dep_des from department where depid=@depid) where userid=@userid fetchnextfrom MyCURSOR into@userid,@depid end close MyCURSOR deallocate MyCURSOR END
posted on
2008-08-22 11:12大米_dr
阅读(270)
评论(0)
编辑收藏举报