?
Just wondering...Hi
The coursor would only live within the context of the execute. If effect,
not usable.
Regards
Mike
"marcmc" wrote:
> ?
> Just wondering...|||thought so. Thx Mike.
"Mike Epprecht (SQL MVP)" wrote:
> Hi
> The coursor would only live within the context of the execute. If effect,
> not usable.
> Regards
> Mike
> "marcmc" wrote:
>|||Actually, it can be available outside the executed scope. Make sure it is a
global cursor. And, you
have to execute the whole lot, like:
EXEC('DECLARE c CURSOR FOR SELECT ...')
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"marcmc" <marcmc@.discussions.microsoft.com> wrote in message
news:2DE21312-AC7D-4950-9A61-A6FC809ADFEA@.microsoft.com...
> thought so. Thx Mike.
> "Mike Epprecht (SQL MVP)" wrote:
>|||Although it is possible to do this hopefully you are aware that most of
the time cursors are a bad idea for data manipulation purposes -
usually there are better solutions and most people will avoid cursors
most of the time.
David Portas
SQL Server MVP
--|||Yes you can.
Example:
use northwind
go
declare @.i int
declare @.c cursor
exec sp_executesql N'set @.c = cursor fast_forward for select orderid from
northwind.dbo.orders open @.c', N'@.c cursor output', @.c output
if cursor_status('variable', '@.c') = 1
begin
while 1 = 1
begin
fetch next from @.c into @.i
if @.@.error != 0 or @.@.fetch_status != 0 break
print @.i
end
close @.c
deallocate @.c
end
go
I am not advocating for cursors.
AMB
"marcmc" wrote:
> ?
> Just wondering...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment