Tuesday, December 2, 2008

PL-SQL Looping

DECLARE CursorTemplate CURSOR
FAST_FORWARD FOR
SELECT Val1, Val2, Val3 FROM Table1

OPEN CursorTemplate

FETCH NEXT FROM CursorTemplate
INTO @Var1, @Var2, @Var3

WHILE (@@FETCH_STATUS = 0)
BEGIN
--do something here w/ your data

FETCH NEXT FROM CursorTemplate
INTO @Var1, @Var2, @Var3

END

CLOSE CursorTemplate
DEALLOCATE CursorTemplate