当前位置: 首页 > 图文教程 > 数据库 > MSSQL > 取汉字拼音首字母的存储过程

MSSQL
SQL Server数据库技术(122)
SQL Server数据库技术(123)
SQL Server数据库技术(124)
SQL Server数据库技术(125)
SQL Server数据库技术(126)
SQL Server数据库技术(127)
SQL Server数据库技术(128)
SQL Server数据库技术(129)
SQL 语法参考手册
存储过程编写经验和优化措施
Sql Server实用操作小技巧集合
更改数据库中表的所属用户的两个方法
SQL SERVER中直接循环写入数据
无数据库日志文件恢复数据库方法两则
维护Sql Server中表的索引
Sql Server全文搜索中文出错的问题
利用数据库日志恢复数据到时间点的操作
SQL Server2000数据库文件损坏时如何恢复
MySQL和SQL Server,到底选择谁?
SQL特性汇总表

MSSQL 中的 取汉字拼音首字母的存储过程


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-30   浏览: 118 ::
收藏到网摘: n/a

  Create  function fun_getPY
 (
    @str nvarchar(4000)
 )
returns nvarchar(4000)
as
begin

  declare @word nchar(1),@PY nvarchar(4000)

  set @PY=''

  while 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'蜶'