在cs中书写
using System;
using System.Data;
using System.Data.Sql;
using System.Data.SqlTypes;
using System.Data;
using Microsoft.SqlServer.Server;
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlString Function1()
{
// Put your code here
return new SqlString("Hello");
}
[SqlFunction]
public static string ClrSplitter(string list, int element)
{
return list.Split(';')[element];
}
};
使用
EXEC sp_configure 'show advanced options','1';
go
reconfigure;
go
EXEC sp_configure 'clr enabled','1' //打开执行clr功能,默认是关闭的
go
select dbo.ClrSplitter('Hello;world',1)