@SnehaAgrawal
Absolutely correct
A while loop and the use of variables to adjust the results of a query
based on the values of the variables definiteley has superior performance than using a cursor.
Never resort to cursors unless you have no other way to achive your goal
and performance is not an issue or the recordset is small.
One correct use for cursors (well correct until I find a better way)
You have a table that lists a set of email addresses that you select as a result of some event.
You loop through the recordset using a cursor so that you can
xp_sendmail to each address.
In this scenario each email sent is similar but different from each other
(not the same)
DYNAMIC QUERIES
These are great and I often use them as a way of not using cursors.
One word of caution however. Don't pass parts of the dynamic query string in as parameters. Doing so opens the door for hackers to use SQL injection.
Just my 2 cents worth