Chapter 3. Ordered Set Functions

Have you ever needed to concatenate elements of a group into one string based on some order? That’s a scenario that an ordered set function could help address. An ordered set function is a type of aggregate function. What distinguishes it from a general set function (like SUM, MIN, MAX, and so on) is that there’s ordering relevance to the calculation, such as the order in which you want to concatenate the elements.

In this chapter, I will discuss ordered set functions and then describe the kinds of solutions they help with. Because they’re not yet supported in Microsoft SQL Server, I will show how to simulate them using what’s provided in SQL Server 2012.

You use ordered set functions in grouped queries much like ...

Get Microsoft® SQL Server® 2012 High-Performance T-SQL Using Window Functions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.