CREATE function [dbo].[Func_GetPY](@str nvarchar(4000))
returns nvarchar(4000)
as
begin
set @str=RTRIM(@str)
declare @word nchar(1),@PY nvarchar(4000)
set @PY=''
while len(@str)>0
begin
--处理常用多音字
if len(@str)>=2
begin
if left(@str,2)='重庆'
begin
set @PY=@PY+'CQ'
if LEN(@str)>2
set @str=right(@str,len(@str)-2)
else
set @str=''
end
if left(@str,2)='西藏'
begin
set @PY=@PY+'XZ'
if LEN(@str)>2
set @str=right(@str,len(@str)-2)
else
set @str=''
end
if left(@str,2)='藏族'
begin
set @PY=@PY+'ZZ'
if LEN(@str)>2
set @str=right(@str,len(@str)-2)
else
set @str=''
end
end
--汉字返回拼音首字母
if LEN(@str)>0
begin
set @word=left(@str,1)
set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901
then (select top 1 PY from (select 'A' as PY,N'驁' as word
union all select 'B',N'簿'
union all select 'C',N'錯'
union all select 'D',N'鵽'
union all select 'E',N'樲'
union all select 'F',N'鰒'
union all select 'G',N'腂'
union all select 'H',N'夻'
union all select 'J',N'攈'
union all select 'K',N'穒'
union all select 'L',N'鱳'
union all select 'M',N'旀'
union all select 'N',N'桛'
union all select 'O',N'漚'
union all select 'P',N'曝'
union all select 'Q',N'囕'
union all select 'R',N'鶸'
union all select 'S',N'蜶'
union all select 'T',N'籜'
union all select 'W',N'鶩'
union all select 'X',N'鑂'
union all select 'Y',N'韻'
union all select 'Z',N'咗'
) T where word>=@word collate Chinese_PRC_CS_AS_KS_WS order by PY ASC
)
else --非汉字字符,返回原字符
@word
end)
set @str=right(@str,len(@str)-1)
end
end
return @PY
end
GO

SqlServer 汉字转换拼音首字母函数的更多相关文章

  1. Excel汉字转换拼音首字母缩写的函数

    打开Excel->工具->宏->Viaual Basic编辑器在弹出来的窗口中对着VBAproject点右键->插入->模块下面会出现一个名为"模块1" ...

  2. sql获取汉字的拼音首字母的函数

    ql获取汉字的拼音首字母   if exists (select * from sysobjects where id = object_id(N'[fn_ChineseToSpell]') and ...

  3. js汉字转拼音首字母

    js汉字转拼音首字母 2018-04-09 阅读 1018 收藏 1 原链:segmentfault.com 分享到:   前端必备图书<JavaScript设计模式与开发实践> > ...

  4. (转载)delphi中获取汉字的拼音首字母

    delphi中获取汉字的拼音首字母1.py: array[216..247] of string = ({216}'CJWGNSPGCGNESYPB' + 'TYYZDXYKYGTDJNMJ' + ' ...

  5. 汉字转拼音首字母的java实现

    工作中经常会遇到的一些排序问题,比如 按汉字的拼音首字母排序,比如人名排序等,就要用到下面的方法了,思路: 1. 获得汉字 2. 将汉字转换成首字母,并记录下(必要时保存到数据库) 3. 按首字母进行 ...

  6. C#获取包括一二级汉字的拼音 首字母

    C#获取包括一二级汉字的拼音 首字母 声母 汉字拼音转换 using System; using System.Collections.Generic; using System.Linq; usin ...

  7. 获取汉字的拼音首字母--pinyin

    var pinyin = (function (){ var Pinyin = function (ops){ this.initialize(ops); }, options = { checkPo ...

  8. sql获取汉字的拼音首字母

    if exists (select * from sysobjects where id = object_id(N'[fn_ChineseToSpell]') and xtype in (N'FN' ...

  9. 简单测试--C#实现中文汉字转拼音首字母

    第一种: 这个是自己写的比较简单的实现方法,要做汉字转拼音首字母,首先应该有一个存储首字母的数组,然后将要转拼音码的汉字与每个首字母开头的第一个汉字即“最小”的汉字作比较,这里的最小指的是按拼音规则比 ...

随机推荐

  1. android studio 程序错误

    一.错误类型: com.android.tools.fd.runtime.BootstrapApplication cannot be cast to 成功修改方式 File --> Setti ...

  2. Servlet源码初探

    年底,公司的事情告一段落,就来捣鼓一下这个Servlet源码,为下一步的spingmvc源码初探做准备 1.Servlet接口 public interface Servlet { void init ...

  3. Unity3D脚本使用:物体调用物体

    如下图4种方式: 方式5 通过Tag定位物体 1.先对物体定义标签Tag,可选已有或自定义 2.通过Tag名称找到对象 注意:如果标签对应多个对象,需使用获取对象集合再进行处理

  4. Signal and Slots

    Signal and Slots 用于对象之间通信. 它是 Qt 的核心特性之一, 并且也是Qt 与其它框架差别最大的部分. 概述 在GUI编程中, 如果我们改变了一个控件, 我们可能想其它控件知道: ...

  5. LINQ_to_SQL语法及实例大全

    LINQ To SQL 语法及实例大全 2011/4/5 目录 LINQ to SQL语句(1)之Where. 2 Where操作... 2 1.简单形式:... 2 2.关系条件形式:... 2 3 ...

  6. centos-mysql 安装

    初学者自编文档,如有错误,请指出,具体命令就不阐述了,不明白 度娘吧! nginx我是编译安装在服务器上 和其他安装应该会有区别 安装路径路径:/usr/local/ 安装包存放位置:/home/ap ...

  7. 多线程随笔一(AutoResetEvent和ManulResetEvent)

    AutoResetEvent和ManulResetEvent是.net中用来做线程的同步的两个类.从类名上不难看出,这两个类的区别在于一个是自动的,一个是手动的(这不是废话嘛).两个类的实现原理大致相 ...

  8. mysql5.5修改字符编码

    因为mysql版本问题,网上各种修改编码的方法都不行,最后找到下面这条,终于解决! [mysqld]下添加: character-set-server=utf8 collation-server=ut ...

  9. MFC窗口程序显示命令行输出窗口的方法

    来源:http://blog.csdn.net/k_shmily/article/details/52596927 WINDOWS为你提供了一系列的API来完成这个功能,例如:ReadConsole, ...

  10. Java Day03 面向对象程序设计

    1.面向对象 面向对象是指一种程序设计泛型,同时也是一种程序开发的方法. 2.类 类是一种抽象的概念,类中包含了数据与对数据的操纵. 具有相同特性(数据元素)和行为(功能)的对象的抽象就是类.类是对象 ...