DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

SQL Server Cursor

04.06.2009
| 4812 views |
  • submit to reddit
        // Syntax for a t-sql server cursor

DECLARE @AuthorID char(11)
	
DECLARE c1 CURSOR READ_ONLY
FOR
SELECT au_id
FROM authors

OPEN c1

FETCH NEXT FROM c1
INTO @AuthorID

WHILE @@FETCH_STATUS = 0
BEGIN

	PRINT @AuthorID

	FETCH NEXT FROM c1
	INTO @AuthorID

END

CLOSE c1
DEALLOCATE c1