MSSQL Cursor

Submitted by:David Villa

Date added:15 January, 2014

Category:PL SQL

Basic definition for a cursor in MSSQL

Tags: cursor , mssql cursor

Code Snippet:

    DECLARE myCursor CURSOR local fast_forward FOR
SELECT col001, col002, col003 FROM DataTable
OPEN myCursor
WHILE 1=1 BEGIN
FETCH next FROM myCursor INTO @var1, @var2, @var3
IF @@FETCH_STATUS <> 0 break

print 'The variable values are: ' + @var1 + ', ' + @var2 + ' and ' + @var3

END

CLOSE myCursor
deallocate myCursor
 
 

Comments