Assembly

Confige Database

ALTER DATABASE Store SET TRUSTWORTHY ON;
EXEC sp_configure 'clr enabled', 1;
RECONFIGURE;

Create Library

namespace LibCalculate
{
    public class Calculate
    {
        public static int Sum(int a, int b)
        {
            return a + b;
        }
    }
}

Create Assembly

ALTER ASSEMBLY CalculateAssembly
FROM 'Source.dll' WITH PERMISSION_SET = SAFE;
GO

Create Function

CREATE FUNCTION Tong(@a INT, @b INT)
RETURNS INT
AS
	EXTERNAL NAME CalculateAssembly.[LibCalculate.Calculate].Sum;
GO

Create Method Split in Library

namespace LibCalculate
{
    public class Calculate
    {
        [SqlFunction(DataAccess=DataAccessKind.None, FillRowMethodName = "MyFillRowMethod", IsDeterministic = true)]
        public static IEnumerable Split(string str, string separator)
        {
            return str.Split(separator.ToCharArray());
        }
        public static void MyFillRowMethod(object theItem, out SqlChars results)
        {
            results = new SqlChars(theItem.ToString());
        }
    }
}

Create Function

CREATE FUNCTION Split(@str NVARCHAR(MAX), @separator NVARCHAR(MAX))
RETURNS TABLE
(
	Results NVARCHAR(MAX)
)
AS
	EXTERNAL NAME CalculateAssembly.[LibCalculate.Calculate].Split;
GO