Create User-defined Aggregates
Applies To: SQL Server 2016
You can create a database object inside SQL Server that is programmed in a CLR assembly. Database objects that can leverage the rich programming model provided by the CLR include triggers, stored procedures, functions, aggregate functions, and types.
Like the built-in aggregate functions provided in Transact-SQL, user-defined aggregate functions perform a calculation on a set of values and return a single value.
Creating a user-defined aggregate function in SQL Server involves the following steps:
Define the user-defined aggregate function as a class in a Microsoft .NET Framework-supported language. For more information about how to program user-defined aggregates in the CLR, see CLR User-Defined Aggregates. Compile this class to build a CLR assembly using the appropriate language compiler.
Register the assembly in SQL Server using the CREATE ASSEMBLY statement. For more information about assemblies in SQL Server, see Assemblies (Database Engine).
Create the user-defined aggregate that references the registered assembly using the CREATE AGGREGATE statement.
To create, modify, or drop an assembly
To create a user-defined aggregate