Cursor / FETCH | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Cursor / FETCH

How do get value this variable @nrcic ? because this code it’s wrong, the response of @nrcic is count of registers. Tks
MACUL
quote:create PROCEDURE sp_TESTE
AS
DECLARE @nrcic CHAR(14)
DECLARE Qtde CURSOR for select numdocument from users
Begin Tran
OPEN Qtde — Perform the first fetch.
FETCH NEXT FROM Qtde INTO @nrcic
— Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
–insert into Ser_Solicitacao
PRINT ‘@nrcic = ‘ + @idtppes FETCH NEXT FROM Qtde
END
CLOSE Qtde
DEALLOCATE Qtde
Commit Tran
GO

www.macul.hpg.com.br www.primeiramao.com.br
(ad free)
I’m not sure exactly what you’re asking, but your second fetch statement (inside the while loop) is incomplete. You’re not assigning the value the fetch returns to anything. It looks like it should be: FETCH NEXT FROM Qtde INTO @nrcic
Similar to your first fetch statement.
I want print the value of @nrcic, where have the second loop ? I need do loop for gerate one search for number of document in other table. like while not End Of File print @nrcic Wend www.macul.hpg.com.br www.primeiramao.com.br
(ad free)
it lacked below the command for next register create PROCEDURE sp_TESTE
AS
DECLARE @nrcic CHAR(14)
DECLARE Qtde CURSOR for select numdocument from users
Begin Tran
OPEN Qtde — Perform the first fetch.
FETCH NEXT FROM Qtde INTO @nrcic
— Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
–insert into Ser_Solicitacao
PRINT ‘@nrcic = ‘ + @idtppes FETCH NEXT FROM Qtde INTO @nrcic
END
CLOSE Qtde
DEALLOCATE Qtde
Commit Tran
GO it repairs on FETCH NEXT FROM Qtde INTO @nrcic in the second time T +
MACUL www.macul.eti.br www.jsafra.com.br
(new concept of bank) www.primeiramao.com.br
(ad free)
]]>