TSQL – Loop Through Result Set WITHOUT Cursors

There is some controversy about using cursors in TSQL.  Overall, I believe they tend to tie up resources and are seen as bad.  So how do you get around using them?  Here’s how.

You can see how cursors are used in my post at TSQL – Simple Loop Through Result Set Using Cursor

To NOT use cursors, you must create a temp table with a “flag” column to indicate whether or not it has been processed yet.  Then, rather than updating the cursor, you update the flag column.  Here’s an example:

2 thoughts on “TSQL – Loop Through Result Set WITHOUT Cursors”

This site uses Akismet to reduce spam. Learn how your comment data is processed.