SQL Server cursors are usually used to process individual rows of data instead of on a complete set of rows. Cursors let you move through rows returned by a SELECT statement one at a time and perform processing on each row. Cursors are much slower and should be avoided as much as possible.
Here’s a way of creating a comma-delimited list without the use of a cursor:
DECLARE @CustomerIDs VARCHAR(8000)
SELECT @CustomerIDs = ISNULL(@CustomerIDs + ',', '') + [CustomerID]
FROM [dbo].[Customers]
SELECT @CustomerIDs