declare @IP varchar(50),@Email varchar(50)
declare tc cursor for select HostIP,UserEmail from RestartLog
open tc
fetch next from tc into @IP , @Email
while @@fetch_status = 0
begin
print @IP+' '+@Email
fetch next from tc into @IP , @Email
end
close tc
deallocate tc //删除对游标变量的引用
sql server 2005 游标使用小例
本文展示了一个使用T-SQL声明并操作游标的示例。通过声明两个变量@IP和@Email来存储从RestartLog表中获取的数据,并使用游标tc遍历这些记录,最后打印出每条记录的IP地址和邮箱。

被折叠的 条评论
为什么被折叠?



