SQL Server Nation
For all of your SQL Server needs.

Cursor Template

Wiki Table of Contents

Page Details

Published by:
TimChapman
on 24 Oct 2009
This page has not yet been rated

Cursor Template

DECLARE @Variable1 INT, @Variable2 INT

DECLARE CursorName
CURSOR FAST_FORWARD
FOR

 SELECT Field1, Field2
 FROM TableName

OPEN CursorName

FETCH NEXT FROM CursorName
INTO @Variable1, @Variable2

WHILE @@FETCH_STATUS = 0
BEGIN
    PRINT 'Operations go here'

    FETCH NEXT FROM CursorName
    INTO @Variable1, @Variable2
END
CLOSE CursorName
DEALLOCATE CursorName

Recent Comments

Leave the first comment for this page.
Copyright SQL Server Nation 2009
Powered by Community Server (Non-Commercial Edition), by Telligent Systems