Alternatives to cursors in SQL Server
What are the alternatives to cursors? I can’t find any other method to move through record sets one at a time.

Software/Hardware used:
ASKED: April 23, 2009  5:49 PM
UPDATED: April 6, 2010  10:28 AM

Answer Wiki:
Answer The main purpose that cursors fulfill is traversing of the row set. Cursors can be best avoided by: a. Using the SQL while loop: Using a while loop we can insert the result set into the temporary table. b. User defined functions: Cursors are sometimes used to perform some calculation on the resultant row set. This cam also be achieved by creating a user defined function to suit the needs ---------- A while loop will be just as slow as a cursor. Functions have there own performance issues to deal with. Your best bet is to use a rowbased process instead. There are several cases when cursors are the best option. If you can provide samples of what you are trying to do better options may be able to be provided.
Last Wiki Answer Submitted:  April 26, 2009  4:13 am  by  Technowise   290 pts.
All Answer Wiki Contributors:  Technowise   290 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _