加载表值时的SQL Server 2008游标?

时间:2014-03-19 08:27:53

标签: database sql-server-2008 cursor

在SQL Server 2008中使用游标时,在哪个语句中将表中的值加载到游标中?

declare @sname nvarchar(50)

declare  cur1 cursor
for
select sname   from tstudent 


open cur1
FETCH NEXT FROM cur1 INTO @sname
print  @sname 
WHILE @@FETCH_STATUS = 0
   BEGIN
      FETCH NEXT FROM cur1 INTO @sname  
      if @@FETCH_STATUS = 0
            print  @sname     
 END
CLOSE cur1
DEALLOCATE cur

1 个答案:

答案 0 :(得分:0)

当您OPEN游标时,使用DECLARE语句中指定的查询从DB填充游标。有关详情,请参阅MSDN