SQL Server has a lot of useful built-in aggregate functions, but for some reason there is nothing built-in (that I know of,) to concatenate strings. This drives me batty. I have this problem over and over again, and have been looking for an elegant solution for a while now. The problem is always the same:
I have data like this:
and I want to get the results, for example, with all the models for Toyota, like this:
It seems like it should be easy – it seems like it should be as simple as Grouping By the Car’s Make column. I’ve seen solutions where you Create and Drop tables, and even methods where you would create and parse xml from your results. It just seems like there should be an easier way.
Well there is.
Finally I have stumbled upon it, and I wanted to share in case anyone else runs in to this problem as much as I do:
In our car example above, this becomes