Over a million developers have joined DZone.

SQL Server Cursor

·
// 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
Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}