Sunday, March 25, 2012

Cursor for loops?

Is there something in T-SQL that is the same as FOR loops in Oracle PL/SQL?
if not, what is the closest equivalent?
DECLARE cursor_name CURSOR FOR
SELECT some_column1, some_column2 FROM some_tables
OPEN cursor_name
FETCH NEXT FROM cursor_name INTO @.some_column1, @.some_column2
WHILE @.@.FETCH_STATUS = 0
BEGIN
/*
do something with data
*/
FETCH NEXT FROM cursor_name INTO @.some_column1, @.some_column2
END
CLOSE cursor_name
DEALLOCATE cursor_name
Read "SQL Server Books Online" about cursors.
Hilarion
sql

No comments:

Post a Comment