Monday, March 19, 2012

Create Comma Separated List- Sql tips and tricks

Create list of Integer type column

[code]

DECLARE @listStr VARCHAR(MAX)

SELECT @listStr = COALESCE(@listStr+',' ,'') + CAST(ColumnName AS Varchar(10))
FROM TableName
SELECT @listStr
GO

[/code]

Replace ColumnName and TableName

No comments: