Skip to content

Instantly share code, notes, and snippets.

@billinkc
Created November 18, 2014 19:27
Show Gist options
  • Save billinkc/5f6411e45d9137a50fe2 to your computer and use it in GitHub Desktop.
Save billinkc/5f6411e45d9137a50fe2 to your computer and use it in GitHub Desktop.
Q&D cursor sample
DECLARE test_cursor CURSOR
READ_ONLY
FOR SELECT TOP 10
SV.name
FROM
master.dbo.spt_values AS SV;
DECLARE @name nvarchar(35)
OPEN test_cursor
FETCH NEXT FROM test_cursor INTO @name
WHILE (@@fetch_status = 0)
BEGIN
PRINT @@FETCH_STATUS
DECLARE @message nvarchar(100)
SELECT @message = N'my name is: ' + @name
PRINT @message
FETCH NEXT FROM test_cursor INTO @name
END
CLOSE test_cursor
DEALLOCATE test_cursor
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment