User SQL cursor when want to traverse rows one by one and perform some operations.

Example:

DECLARE vend_cursor CURSOR

FOR SELECT * FROM Purchasing.Vendor

OPEN vend_cursor

FETCH NEXT FROM vend_cursor

WHILE @@FETCH_STATUS = 0

BEGIN

--Perfrom some operation

END

CLOSE vendor_cursor;

DEALLOCATE vendor_cursor;