SQL Cursors

[code lang="sql"]

declare @datefrom datetime
declare @clientid int

DECLARE arrears_client_cursor CURSOR FOR
SELECT top 10 cc.id
FROM client_creditcontrol ccc
INNER JOIN client_contact cc ON cc.id = ccc.clientid

OPEN arrears_client_cursor
FETCH NEXT FROM arrears_client_cursor INTO @clientid

WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @clientid

FETCH NEXT FROM arrears_client_cursor INTO @clientid
END

CLOSE arrears_client_cursor
DEALLOCATE arrears_client_cursor

[/code]
Posted in SQL