Click here to Skip to main content
11,414,619 members (66,197 online)
Click here to Skip to main content

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

, 25 Feb 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
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), '"/><row r="', ', ' ), '">', '' ), '</row>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

e-Lopes

Brazil Brazil
No Biography provided

Comments and Discussions

 
GeneralReason for my vote of 5 nice one Pin
nikhi _singh26-Feb-12 18:45
membernikhi _singh26-Feb-12 18:45 
Generalif object_id('people') is Not Null drop view people; GO crea... Pin
pandiyarajk26-Feb-12 8:49
grouppandiyarajk26-Feb-12 8:49 
GeneralThat doesn't really do the same job - the original concatena... Pin
OriginalGriff23-Feb-12 0:22
mvpOriginalGriff23-Feb-12 0:22 
GeneralRe: The vision I just used to illustrate, change the view by the... Pin
e-Lopes25-Feb-12 14:25
membere-Lopes25-Feb-12 14:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150427.4 | Last Updated 25 Feb 2012
Article Copyright 2012 by e-Lopes
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid