declare MyCursor cursor for select Name from #table --定义游标,游标数据集来源临时表#table open MyCursor --打开游标以供下面代码使用 fetch next from MyCursor into @name --将游标指向的值赋值给临时变量@name,游标指向下一条数据 while @@FETCH_STATUS=0 --判断游标是否到最后一条记录 begin select @name fetch next from MyCursor into @name end close MyCursor --关闭游标 deallocate MyCursor -- 释放最后的游标引用时
|