EDIT
Resolvi adicionar um exemplo completo e as estatisticas.
TABELA
CREATE TABLE [dbo].[CursorTeste](
[CursorTesteID] [int] IDENTITY(1,1) NOT NULL,
[Coluna1] [uniqueidentifier] NOT NULL,
[Coluna2] [uniqueidentifier] NOT NULL,
[Coluna3] [uniqueidentifier] NOT NULL,
CONSTRAINT [PK_CursorTeste] PRIMARY KEY CLUSTERED
(
[CursorTesteID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
INSERT
DECLARE @count int;
SET @count = 0;
WHILE (@count < 10000)
BEGIN
INSERT INTO CursorTeste VALUES (NEWID(), NEWID(), NEWID());
SET @count = @count + 1;
END
CURSOR
DECLARE @coluna1 int;uniqueidentifier;
DECLARE @coluna2 int;uniqueidentifier;
DECLARE @coluna2@coluna3 int;uniqueidentifier;
DECLARE @CURSOR_tabela@CURSOR_teste CURSOR;
SELECTSET @CURSOR_tabela@CURSOR_teste = CURSOR LOCAL FAST_FORWARD FOR
SELECT Coluna1, Coluna2, Coluna3
FROM Tabela
WHERE Coluna4 = @coluna4;CursorTeste
OPEN @CURSOR_tabela;@CURSOR_teste
WHILE (1 = 1)
BEGIN
FETCH NEXT @CURSOR_tabela
FROM @CURSOR_teste INTO @coluna1, @coluna2, @coluna2;
@coluna3;
IF (@@FETCH_STATUS <> 0)
BEGIN
BREAK;
END
PRINT '{ ' + cast(@coluna1 PRINTas 'Executarvarchar(50)) alguma+ operação' aqui';} - { ' + cast(@coluna2 as varchar(50)) + ' } - { ' + cast(@coluna3 as varchar(50)) + ' }';
END
CLOSE @CURSOR_tabela@CURSOR_teste
DEALLOCATE @CURSOR_tabela@CURSOR_teste
DECLARE @coluna1 int;uniqueidentifier;
DECLARE @coluna2 int;uniqueidentifier;
DECLARE @coluna2@coluna3 int;uniqueidentifier;
DECLARE @rowNumber@indice int;int
DECLARE @count int
DECLARE @tabela table(
RowNumber int identity,
Coluna1 intuniqueidentifier not null,
Coluna2 intuniqueidentifier not null,
Coluna3 intuniqueidentifier not null,
PRIMARY KEY (RowNumber)
);
INSERT INTO @tabela
SELECT Coluna1, Coluna2, Coluna3
FROM TabelaCursorTeste
WHERE
SET Coluna4@count = @coluna4;
(SELECT COUNT(RowNumber) FROM @tabela)
SET @rowNumber@indice = 1;
WHILE (1@indice =<= 1@count)
BEGIN
SELECT
@rowNumber@indice = RowNumber + 1,
@coluna1 = Coluna1,
@coluna2 = Coluna2,
@coluna3 = Coluna3
FROM
@tabela
WHERE RowNumber = @rowNumber@indice
PRINT cast(@indice as varchar(50))
+ ' { ' IF+ cast(@coluna1 isas nullvarchar(50)
BEGIN
) + ' } - { ' BREAK;
+ cast(@coluna2 as varchar(50)) END
+ ' } -
{ ' + cast(@coluna3 PRINTas 'Executarvarchar(50)) alguma+ operação' aqui';}';
END