This script is a simple usage of cursors in MSSQL: