Hi All,
Recently got into a situation of grouping set of
data with a comma delimited. Here is the requirement.
I have a table like this below,
And the way data should be shown as
So let us create a sample data set to achieve this:
create table #t1 (ID INT, Name Varchar(10))
Insert into #t1
Select 1, 'a' Union
Select 1, 'b' Union
Select 1, 'c' Union
Select 2, 'e' Union
Select 2, 'f' Union
Select 2, 'a' Union
Select 2, 'H' Union
Select 3, 'X'
|
And query for the output
SELECT ID
,STUFF((SELECT ', ' + CAST(Name AS VARCHAR(10))
FROM #t1
WHERE ID = t.ID
FOR XML PATH(''), TYPE).value('.','NVARCHAR(MAX)'),1,2,' ') Merge_output
FROM #t1 t
GROUP BY ID
|
Thank you for sharing wonderful information with us to get some idea about that content.
ReplyDeleteBest Msbi Online Training
Msbi Online Training in Hyderabad