Tip of the Day : How to Get a List of Stored Procedures Within a Database

SQL Server Helper - Tip of the Day

How to Create a Comma-Delimited List Without Using a Cursor

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

Back to Tip of the Day List Next Tip