


Standard SQL defines a concept called ordered set function which is a set function that has ordering relevance. Ordered set functions can be applied to sets defined as groups in grouped queries. The standard provides a clause called WITHIN GROUP where you can provide the ordering specification. The standard defines some specific types of ordered set functions like inverse distribution functions and hypothetical set functions. However, what I find to be most important is product support for the general concept in the engine, including optimization, parsing, etc., to make it easy to add specific cases. As of Microsoft SQL Server 2012 there’s no support yet for ordered set functions. Here are a few examples for types of functions that would work well as ordered set functions: 1. Grouped String Concatenation 2. Ordered CLR Aggregates 3. Inverse Distribution Functions 4. Hypothetical Set Functions 5. Offset Functions Due to a character limit in the description of the connect item there's no space for the full request here. The document http://tsql.solidq.com/OSF.doc provides the detailed feature request describing the concept as well as different examples where such support could be useful.