Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi i have a table having 5 columns

ID | ReportId  |  Col1 |   Col2   |col3
1     |1            |a     |Cola    |col3a
2     |2            |b     |colb    |col3b
3     |1            |c     |null    |col3c
4     |3            |d     |cold    |col3d
5     |3            |e     |cole    |null


i am trying a query to write a select query where i can get the columns in comma separated way using group by

Output sample

ReportId    |Col1   |Col2          |col3
1            |a,c   |Cola,null     |col3a,col3c
2            |b     |colb          |col3b
3            |d,e   |cold,cole     |col3d,null


please help me with this
Posted
Updated 19-Apr-15 23:34pm
v2

1 solution

There is no build-in function in SQL server to aggregate strings. If you cannot shift the logic to your presentation layer, where it naturally belongs btw, then I suggest you do some reading on how to aggregate strings in SQL server. For example here on Code Project: String Aggregation in the World of SQL Server[^].

Be warned though, there is no nice or elegant solution!
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900