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 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 Pinmembernikhi _singh26-Feb-12 18:45 
Generalif object_id('people') is Not Null drop view people; GO crea... Pingrouppandiyarajk26-Feb-12 8:49 
GeneralThat doesn't really do the same job - the original concatena... PinmvpOriginalGriff23-Feb-12 0:22 
GeneralRe: The vision I just used to illustrate, change the view by the... Pinmembere-Lopes25-Feb-12 14: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    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.141223.1 | Last Updated 25 Feb 2012
Article Copyright 2012 by e-Lopes
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid