Posted by: Red Souldier | May 19, 2009

Microsoft SQL Server 2005 Cursor Example

DECLARE @id INT
DECLARE @name varchar(25)
DECLARE db_cursor CURSOR FOR
SELECT id,name From myTable
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @id, @name

WHILE @@FETCH_STATUS = 0
BEGIN
— do something
FETCH NEXT FROM db_cursor INTO @id, @name
END

CLOSE db_cursor
DEALLOCATE db_cursor

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: