这个方法比较简单,用Microsoft.VisualBasic命名空间下强大的字符串处理函数就可以了
c#代码如下,编译为BigConvertor.dll
-------------------------------------------------------------------------------- 代码如下:
using System;
using System.Data.sqlTypes;
using Microsoft.sqlServer.Server; public partial class UserDefinedFunctions
{
[Microsoft.sqlServer.Server.sqlFunction ]
public static sqlString BigToGB(sqlString inString)
{
if (inString.IsNull) return sqlString .Null;
return (Microsoft.VisualBasic.Strings .StrConv(inString.Value,Microsoft.VisualBasic.VbStrConv .SimplifiedChinese,0));
}
[Microsoft.sqlServer.Server.sqlFunction ]
public static sqlString GBToBig(sqlString inString)
{
if (inString.IsNull) return sqlString .Null;
return (Microsoft.VisualBasic.Strings .StrConv(inString.Value,Microsoft.VisualBasic.VbStrConv .TraditionalChinese,0));
}
};
using System.Data.sqlTypes;
using Microsoft.sqlServer.Server; public partial class UserDefinedFunctions
{
[Microsoft.sqlServer.Server.sqlFunction ]
public static sqlString BigToGB(sqlString inString)
{
if (inString.IsNull) return sqlString .Null;
return (Microsoft.VisualBasic.Strings .StrConv(inString.Value,Microsoft.VisualBasic.VbStrConv .SimplifiedChinese,0));
}
[Microsoft.sqlServer.Server.sqlFunction ]
public static sqlString GBToBig(sqlString inString)
{
if (inString.IsNull) return sqlString .Null;
return (Microsoft.VisualBasic.Strings .StrConv(inString.Value,Microsoft.VisualBasic.VbStrConv .TraditionalChinese,0));
}
};
--------------------------------------------------------------------------------
部署代码如下
-------------------------------------------------------------------------------- 代码如下:
CREATE ASSEMBLY BigConvertor FROM 'E:/sqlclrdata/BigConvertor.dll' WITH PERMISSION_SET = UnSAFE;
--
go
CREATE FUNCTION dbo. xfn_BigToGB
(
@value nvarchar ( max )
)
RETURNS nvarchar ( max )
AS EXTERNAL NAME BigConvertor. UserDefinedFunctions. BigToGB
go
CREATE FUNCTION dbo. xfn_GBToBig
(
@value nvarchar ( max )
)
RETURNS nvarchar ( max )
AS EXTERNAL NAME BigConvertor. UserDefinedFunctions. GBToBig go
--
go
CREATE FUNCTION dbo. xfn_BigToGB
(
@value nvarchar ( max )
)
RETURNS nvarchar ( max )
AS EXTERNAL NAME BigConvertor. UserDefinedFunctions. BigToGB
go
CREATE FUNCTION dbo. xfn_GBToBig
(
@value nvarchar ( max )
)
RETURNS nvarchar ( max )
AS EXTERNAL NAME BigConvertor. UserDefinedFunctions. GBToBig go
--------------------------------------------------------------------------------
测试代码如下
--------------------------------------------------------------------------------/* 测试 */
select dbo. xfn_GBToBig( ' 简体与繁体文的转换 ' )
-- 簡體與繁體文的轉換
select dbo. xfn_BigToGB( ' 簡體與繁體文的轉換 ' )
-- 简体与繁体文的转换
原文链接:https://www.f2er.com/mssql/66284.html