Click here to Skip to main content
Click here to Skip to main content

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)

About the Author

e-Lopes

Brazil Brazil
No Biography provided

Comments and Discussions

 
GeneralReason for my vote of 5 nice one Pinmembernikhi _singh26-Feb-12 17:45 
Generalif object_id('people') is Not Null drop view people; GO crea... Pingrouppandiyarajk26-Feb-12 7:49 
GeneralThat doesn't really do the same job - the original concatena... PinmvpOriginalGriff22-Feb-12 23:22 
GeneralRe: The vision I just used to illustrate, change the view by the... Pinmembere-Lopes25-Feb-12 13: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 | Mobile
Web03 | 2.8.140709.1 | Last Updated 25 Feb 2012
Article Copyright 2012 by e-Lopes
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid