King

business intelligence ,is my love。

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

问题:例如有一个字段内容为 :我是中國人 ,效果是转为“我是中国人

思路:把"國"换为”国“即可,同理如果字符中有多个繁体字则一一替换。

操作:建立简繁体字典表codetable

内容大致如下:

--------------------------------------------------------------

gb big
执 執
纸 紙
挚 摯
掷 擲
帜 幟
质 質

......

国 國

----------------------------------------------------------------

创建自定义方法:如下语法

create function [dbo].[f_GB2BIG1](
@str nvarchar(4000), --要转换的字符串
@toBIG bit --转换标志,为1,表示 GB-->BIG,否则是 BIG-->GB
)returns nvarchar(4000)
as
begin
if @toBIG=1
select @str=replace(@str,gb,big)
from codetable
where charindex(gb,@str)>0
else
select @str=replace(@str,big,gb)
from codetable
where charindex(big,@str)>0
return(@str)
end

--调用and测试

 (1):select   dbo.f_GB2BIG('我是中國國人',0)   

 

 (2):select   dbo.f_GB2BIG('我是中国国人',1)   

注意的是简繁体字典可能一直在更新,比较完整的版本请到http://vdisk.weibo.com/s/udWF5 下载

 

 

 

 

posted on 2013-03-19 12:29  kingstudy  阅读(6968)  评论(2编辑  收藏  举报