-- Collection of code snippets by Arne Vajhøj 
-- (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
CREATE PROCEDURE TEST_CURSOR AS

DECLARE @n INTEGER, @F2 VARCHAR(50)

SELECT @n = 1

DECLARE c CURSOR FOR
SELECT F2 FROM T1

OPEN c

FETCH NEXT FROM c INTO @F2

WHILE @@FETCH_STATUS = 0
BEGIN
       SELECT @n = @n + 1
       PRINT CAST(@n AS VARCHAR(8)) + " " + @F2
       FETCH NEXT FROM c INTO @F2
END

CLOSE c

DEALLOCATE c

GO
