I have come across a problem while doing
development. Finally I have sorted this problem. So I have decided to write an
blog on this. The problem and solution is as below:-
Problem
I have table as given below

Now I want to convert state row values to one string value.
Ex: Andhra Pradesh, Arunachal Pradesh, Assam,
Maharashtra
Solutions
For the above problem, below are different
queries to achieve this.
Query 1: Using "COALESCE" function
DECLARE
@temp VARCHAR(MAX)
SELECT
@temp =
COALESCE(@temp+',
' ,'')
+
state
FROM
[dbo].[country]
SELECT
@temp
Query 2: Using without "COALESCE" function

Umesh AggarwalPosted Aug 6, 2020, 7:10 AM
Sir do you have a solution with unique values
kalai romiPosted Dec 5, 2019, 7:00 AM
Try this below example too,,,i hope it helps..
kalai romiPosted Dec 5, 2019, 6:59 AM
SELECT STUFF((SELECT ', ' + Column Name FROM Table Name FOR XML PATH('')),1,2,'') as [Column Name]
Abhilash SenguptaPosted Jan 18, 2018, 5:22 AM
I want to implement the same but using int values. Can you help me out? Thanks.
Atul KalePosted Nov 3, 2017, 5:36 AM
I want to implement exactly same scenario in PDW server. Above queries/functions do not work in PDW. Could you please help on this?
Manav PandyaPosted Jul 13, 2017, 8:01 AM
Nice one ............
Onkar GuptaPosted Jul 30, 2015, 7:25 AM
good job sir ji
vikrant choudharyPosted Sep 12, 2014, 5:40 AM
Thanks a lot.. :)