Please see my other Database Development articles.
Performing iterative actions.
Update: SQL Server 2008 introduced a new feature to T-SQL, Common Table Expressions (CTEs) which is meant to replace the use of cursors. For more information read my WITH article.
Sometimes business requirements demands that complex actions must be performed on recordsets in such a manner that each row must be acted upon before proceeding to the next (SELECT, INSERT, etc.).
The following example demonstrates how to retrieve data from a table, store it into a temporary table, then return that data.