syscomments

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 |

Feedback

Gravatar

# re: Aggregate Functions

http://sqlblog.com/blogs/alexander_kuznetsov/archive/2009/03/29/we-need-an-olap-function-for-string-concatenation.aspx
4/16/2009 1:21 PM | Alex K
Gravatar

# 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
Gravatar

# re: Aggregate Functions

Or, if you are on SQL Server 2005 or later, use the FOR XML clause?
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254
4/16/2009 11:53 PM | Peso
Gravatar

# 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?

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

Powered by:
Powered By Subtext Powered By ASP.NET