65.9K
CodeProject is changing. Read more.
Home

Concatenate many rows into a single text string using SQL Server 2008

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

Feb 25, 2012

CPOL
viewsIcon

20600

How to concatenate many rows into a single text string using SQL Server 2008.

Greetings, try this:
if object_id('people') is Not Null drop view people;
GO
create view people ( Name ) 
as
select 'RAM'
union all select 'GURU'
union all select 'Sundar'
union all select 'Shyam'
union all select 'Inba'
union all select 'Kalai'
GO
select replace( replace( replace( (select Name as R from People for XML raw), '"/>', '' ), '