Microsoft SQL server let us implement and store SQL functions and stored procedures in .NET assemblies.
Essentially, this feature let you almost do anything with MSSQL including calling external web services, complex computations, encryption e.t.c
Here are the basic steps required to set-up a working solution:
Run this in SQL query window:
sp_configure 'clr enabled', 1
GO
RECONFIGURE
GO
In visual studio create an SQL clr database project.
If you need to do more than a simple computation, set the assembly to "UNSAFE" in the database tab permission level.
Add TRUSTWORTHY permission to your database.
ALTER DATABASE DbName SET TRUSTWORTHY ON;