Click here to Skip to main content
11,573,935 members (69,135 online)
Click here to Skip to main content

SQL: Column Values as Comma Separated String

, 10 Aug 2013 CPOL 41.2K 5
Rate this:
Please Sign up or sign in to vote.
Column values as comma separated string in SQL


I have a table as shown below, which has Country_Code and languages that are spoken by different people living in a country. I need to retrieve distinct languages spoken in a country based on the Country_Code column as a comma separated string.

SQL Statement

The following statement shows how it can be achieved:

declare @str varchar(1000)

SELECT @str= coalesce(@str + ', ', '') + a.CountryLang_Desc 
FROM (SELECT DISTINCT CountryLang_Desc from CountryLanguages where Country_Code='IN') a

print @str 


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


About the Author

Srinivas Kalabarigi
Software Developer (Senior)
India India

Around 8 years of software development experience and involved in analysis, design, development, testing and deployment of enterprise web applications for government, healthcare and banking domain with good exposure to object-oriented design, software architectures, design patterns, test-driven development and agile practices.

Educational Background
  • Post Graduation in Computer Science from Andhra University, India.
  • Graduation in Mathematics, Electronics and Computer Science from Andhra University, India.
  • Diploma in Software Technology from CMC Ltd., India.

You may also be interested in...

Comments and Discussions

Questioncoalesce query Pin
Tirthankar Dey1-Sep-13 21:24
memberTirthankar Dey1-Sep-13 21:24 
QuestionWhat about NULL values? Pin
kast21815-Aug-13 23:47
memberkast21815-Aug-13 23:47 

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
Web03 | 2.8.150624.2 | Last Updated 10 Aug 2013
Article Copyright 2013 by Srinivas Kalabarigi
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid