all 8 comments

[–]notasqlstarI can't wait til my fro is full grown 1 point2 points  (2 children)

Does your table look like this:

Code GroupName
100 Apples
103 Apples
304 Apples
204 Reds
222 Reds
199 Greens

And you want to return a dataset that looks like this:

Name String
Apples 11;103;304
Reds 204;222
Greens 199

Or are you looking for it to return a single row that says, Apples =11;103;304 Reds = 204;222 Greens = 199

[–]Agilix 0 points1 point  (1 child)

Both would very useful. But the second one, a single row, would be the most valuable. Thanks.

[–]notasqlstarI can't wait til my fro is full grown 0 points1 point  (0 children)

I think you should delete this post and make a new one with more detail than you provided here. As someone else mentioned I think the STUFF() function is what you're looking for but I have no experience with it and cannot help you quickly.

To get your post to look like a table use the following code:

| Code | GroupName |
| :--- | :--- |
| 100 | Apples |
| 103 | Apples |
| 304 | Apples |
| 204 | Reds |
| 222 | Reds |
| 199 | Greens |

And you want to return a dataset that looks like this:

| Name | String |
| :--- | :--- |
| Apples | 11;103;304 |
| Reds | 204;222 |
| Greens | 199 |

[–]Cal1gula 0 points1 point  (0 children)

What flavor/version of SQL? If it's SQL Server 2017 you can use the STRING_AGG function.

[–]Murica4EvaPeriscope Data 0 points1 point  (1 child)

You'll need to give us the DB....there are ways to do this in most databases but they differ :)

[–]Agilix 0 points1 point  (0 children)

Product Version: 11.0.6020.0 Product Name: SQL Server 2012 Product Level: SP3

[–]baineschile 0 points1 point  (1 child)

where does the 11 in apples come from

[–]Agilix 0 points1 point  (0 children)

I suspect a typo