Wednesday, May 24, 2006

Generic Cursor Template

Generic CURSOR Template -
DECLARE @Variable VARCHAR(200)
DECLARE CURSORNAME CURSOR FOR
SELECT ColumnName FROM Table         
OPEN CURSORNAME
FETCH NEXT FROM CURSORNAME INTO @Variable

WHILE @@FETCH_STATUS = 0
BEGIN

-- DO STUFF HERE !!

FETCH NEXT FROM CURSORNAME INTO @Variable
END

CLOSE CURSORNAME
DEALLOCATE CURSORNAME

No comments: