Hi, Einar,
A cursor will work - but cursor performance is generally lackluster. If you have a few dozen rows, it's not too bad, but for anything much larger, it's been documented to affect server performance.
If it's going to be a small # of rows, you can do....
DECLARE MyCursor CURSOR FORWARD_ONLY READ_ONLY FOR SELECT MyColumnName1, MyColumnName2 From blah blah blah
OPEN MyCursor
FETCH Next FROM MyCursor INTO @MyColumnName1, @MyColumnName2
WHILE (@@FETCH_STATUS=0) BEGIN
FETCH Next FROM MyCursor INTO @MyColumnName1, @MyColumnName2
END
CLOSE MyCursor
DEALLOCATE MyCursor
Here's a URL with some tips on cursors (including performance tips).
http://www.mssqlcity.com/Tips/tipCursor.htmAlso...
http://www.databasejournal.com/features/mssql/article.php/1439731Again, if you're talking about a large amount of data, performance can be very slow.
SQL Server 2005 has new capabilities that "might" help, depending on your situation. If you can post some specifics about what you're looking to do, maybe we can go from there. Unless it's something really unusual, often you can use subqueries or derived tables or some other means if you need to do row-by-row operations.
Kevin