Click here to Skip to main content
13,090,503 members (61,821 online)
Click here to Skip to main content
Add your own
alternative version

Stats

13.5K views
1 bookmarked
Posted 25 Feb 2012

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

, 25 Feb 2012
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

You may also be interested in...

Pro
Pro

Comments and Discussions

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

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

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

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