Click here to Skip to main content
13,289,626 members (59,117 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 8 Mar 2012

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

, 8 Mar 2012
Rate this:
Please Sign up or sign in to vote.
Using COALESCE function - concatenate many rows into a single text string output in SQL Server.

The following code is used to concatenate many rows into a single text string with comma separated using SQL Server COALESCE function.

My table format is like this:


I need output like this:

"RAM, GURU, Sundar, Shyam, Inba, Kalai"

I use the following query:

DECLARE @Names VARCHAR(8000)  
SELECT @Names = COALESCE(@Names + ', ', '') + Name FROM People


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


About the Author

Ramanujam Shankar
Web Developer Mahindra Logisoft Business Solution Limited, Chenn
India India
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionThanks great help.. Extend to same discussion Pin
abdulkalam.m8-Mar-16 4:22
memberabdulkalam.m8-Mar-16 4:22 
AnswerThank you Pin
aravinth santosh11-May-15 0:01
memberaravinth santosh11-May-15 0:01 
Generalmy vote is 5 (with stars) Pin
Member 1070385724-Apr-15 16:33
memberMember 1070385724-Apr-15 16:33 
QuestionThis is mostly... just... genius. Pin
Member 15341609-Oct-14 7:50
memberMember 15341609-Oct-14 7:50 
QuestionSELECT Query Pin
Kannan Karthikeyan6-Oct-14 11:16
memberKannan Karthikeyan6-Oct-14 11:16 
QuestionTo avoid the ", " at the beginning of the string Pin
Member 101685651-Oct-13 0:47
memberMember 101685651-Oct-13 0:47 
QuestionConcerned about the use of COALESCE vs a Case Function Pin
dalyteaching23-Aug-13 4:51
memberdalyteaching23-Aug-13 4:51 
GeneralMy vote of 5 Pin
Sk. Tajbir4-Feb-13 23:31
memberSk. Tajbir4-Feb-13 23:31 
Generalc# Pin
Member 823748321-Dec-12 10:06
memberMember 823748321-Dec-12 10:06 
GeneralMy vote of 5 Pin
wolfcoder7514-Dec-12 10:53
memberwolfcoder7514-Dec-12 10:53 
QuestionFor both sql server 2005 and 2008 Pin
Shawn02713-Mar-12 3:45
memberShawn02713-Mar-12 3:45 
AnswerRe: For both sql server 2005 and 2008 Pin
wolfcoder7514-Dec-12 10:58
memberwolfcoder7514-Dec-12 10:58 
Questionbla bla Pin
sajithinnate11-Mar-12 21:18
membersajithinnate11-Mar-12 21:18 

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
Web04 | 2.8.171207.1 | Last Updated 8 Mar 2012
Article Copyright 2012 by Ramanujam Shankar
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid