Hi,
I want to fetch some data row by row and some operations perform on each row so, suggest to me which one is better for that case and why?
Is cursor better or While loop in Store procedure?
ex -
- I want to cumulative frequency from the data
- I want to copy each row in separate temp table.

Vishal JoshiPosted Oct 3, 2022, 5:51 AM
I almost always use a cursor to loop through records when necessary. The cursor format is a little more intuitive for me and, since I just use the constructs to loop through the result set once, it makes sense to use the FAST_FORWARD cursor. Remember that the type of cursor you use will have a huge impact on the performance of your looping construct.
Use SQL Server Profiler to check logical reads and you can check which one is better in a particular situation.
Rajanikant HawaldarPosted Oct 2, 2022, 3:24 PM
I always use cursor in this situations and work well.