Skip to content

Instantly share code, notes, and snippets.

@astannard
Last active December 25, 2015 18:39
Show Gist options
  • Select an option

  • Save astannard/7022405 to your computer and use it in GitHub Desktop.

Select an option

Save astannard/7022405 to your computer and use it in GitHub Desktop.
T-SQL Cursor
DECLARE @Id int
DECLARE TableCursor CURSOR LOCAL FAST_FORWARD FOR
SELECT Id
FROM dbo.TABLENAME
OPEN TableCursor
FETCH NEXT FROM TableCursor INTO @Id
WHILE @@FETCH_STATUS=0
BEGIN
DO STUFF
FETCH NEXT FROM TableCursor INTO @Id
END
CLOSE TableCursor
DEALLOCATE TableCursor
@astannard
Copy link
Copy Markdown
Author

Optimized to be specific to the connection and the cursor is optimized for in order traversal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment