--声明变量
declare @IMType varchar(10),@IMResourceID varchar(10)
--定义游标
declare information_cursor cursor for
select [IMType],[IMResourceID] FROM [BJYX].[dbo].[Information]
--打开游标
open information_cursor
--搜索行,并将数据存储在变量中
Fetch next from information_cursor into @IMType,@IMResourceID
--遍历结果集开始
While @@FETCH_STATUS=0
begin
--这里面可以对某一行进行想要的处理
print @IMType+space(2)+@IMResourceID
--继续读取行数据
Fetch next from information_cursor into @IMType,@IMResourceID
end
--遍历结果集结束
--关闭游标
Close information_cursor
--释放游标
deallocate information_cursor
原文:http://www.cnblogs.com/alphafly/p/3955054.html