RocketScientist's Miscellaneous Ramblings
posts - 76, comments - 354, trackbacks - 3

Aggregate Functions

I've run into this before, I ran into it today, and I'll probably run into it again.

Why isn't there an aggregate function that concatenates strings?

Besides the obvious "string don't get that big" (which I'd manage by manipulating my group by to fit) why not?

Something like:

CONCAT_AGG(column, separator)

Where separator is a varchar that determines what goes between each string (space, comma-space, whatever).

This would be pretty dang handy.

Print | posted on Thursday, April 16, 2009 11:25 AM |



# re: Aggregate Functions
4/16/2009 1:21 PM | Alex K

# re: Aggregate Functions

I wondered that too, and just created a SQLCLR custom aggregation function to do it.. works pretty slick..
4/16/2009 1:40 PM | Steve

# re: Aggregate Functions

Or, if you are on SQL Server 2005 or later, use the FOR XML clause?
4/16/2009 11:53 PM | Peso

# re: Aggregate Functions

...because there's no support for ORDER BY in aggregate functions yet.

If you're going to concatenate strings, you need to tell it what order to aggregate them, right?

4/17/2009 2:45 AM | Rob Farley
Comments have been closed on this topic.

Powered by:
Powered By Subtext Powered By ASP.NET