说明:用动态字符串打开游标
declare @lcSqlcommand nvarchar(4000),
@test cursor,
@lnSucc int,
@name varchar(50)
set @lcSqlcommand=
'use northwind
set @test=cursor local scroll for
select name
from sysobjects
order by name
open @test
'
Exec @lnSucc=sp_executesql @lcSqlCommand,
N'@test cursor OutPut',
@test output
fetch next from @test into @name
while @@fetch_status=0
begin
print @name
fetch next from @test into @name
end
select name
from sysobjects
order by name