SQL Server Cursor Basic Example
DECLARE @CustomerId int ,
@Email VARCHAR(500)
DECLARE db_cursor CURSOR
FOR
-- write your query to store a result set in Cursor
SELECT CustomerId ,
Email
FROM dbo.Customers
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @CustomerId, @Email
WHILE @@FETCH_STATUS = 0
BEGIN
-- Do your stuff with the variables
PRINT Email
FETCH NEXT FROM db_cursor INTO @CustomerId, @Email
END
CLOSE db_cursor
DEALLOCATE db_cursor