Search

Tuesday, July 24, 2012

Create a Comma-Delimited List Without Using a Cursor

Cursors in SQL Server are used to process a complete set of rows one by one. Cursors are much slower and we should avoid using Cursors.

Use below query to create comma-delimited list without th use of a Cursor:

DECLARE @CardIDIDs  VARCHAR(MAX)


SELECT @CardIDIDs = ISNULL(@CardIDIDs + ',', '') + [CardID] FROM CustomerMaster


SELECT @CardIDIDs

No comments:

Post a Comment