You are here


TSQL – Simple Loop Through Result Set Using Cursor

This is the basic query text to use whenever you need to loop through a result set in SQL Server using TSQL. In this example we are getting every database name and printing it out.

TSQL – Loop Through Result Set WITHOUT Cursors

There is a time and a place for everything, cursors included. Here is one way to avoid using them.

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:

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
8 + 9 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer