The information in this article applies to:
SUMMARYIt is often desirable to simulate a cursor-like FETCH-NEXT logic in a stored procedure, trigger, or Transact-SQL batch. For instance, it might be necessary to process all the rows in a table sequentially in order to avoid filling up the transaction log. This article will discuss various methods for accomplishing this task. MORE INFORMATION
SQL Server 4.2x does not implement server side cursoring. However, it
is possible to iterate through a results set using Transact-SQL
statements.
A second method is by using the min() function to "walk" a table one row at a time. This method would catch new rows that had been added after the stored procedure began execution, provided that the new row had a unique identifier greater than the current row being processed in the query.
NOTE: Examples 1 and 2 both assume that a unique identifier exists for each
row in the source table. In some cases, no unique identifier may exist. If
this is the case, the temp table method may be modified to use a newly
created key column. Example 3 illustrates this method.
Additional query words: Windows NT
Keywords : kbtool SSrvTran_SQL SSrvWinNT |
Last Reviewed: March 18, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |