using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
public partial class UserDefinedFunctions {
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlInt64 Function1(SqlInt32 a, SqlInt32 b) {
return a + b; // 簡易加法示範
}
}
Build → Deploy (或右鍵專案 → Deploy)
-- SSMS 執行
sp_configure 'clr enabled', 1;
GO
RECONFIGURE;
GO
-- 測試函數
SELECT dbo.Function1(10, 20); -- 返回 30

驗證 CLR 整合運作正常,函數成功回傳加法結果。