一个效率很高的汉字转拼音首字母的函数

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

转自:http://www.cnblogs.com/zhuisuo/archive/2011/01/12/1933842.html

create   function   [dbo].[fn_getpy]
(@str   nvarchar(4000)) 
returns   nvarchar(4000) 
as 
begin 
declare   @str_len   int,@result   nvarchar(4000) ,@crs nvarchar(1)
set @str_len=len(@str)
set @result= ' ' 
    while   @str_len> 0 
    begin 
set  @crs=substring(@str,@str_len,1)
 
   select  @str_len=@str_len-1,@result=
     case  
     when @crs>='帀' then 'Z'
     when @crs>='丫' then 'Y'
     when @crs>='夕' then 'X'
     when @crs>='屲' then 'W'
     when @crs>='他' then 'T'
     when @crs>='仨' then 'S'
     when @crs>='呥' then 'R'
     when @crs>='七' then 'Q'
     when @crs>='妑' then 'P'
     when @crs>='噢' then 'O'
     when @crs>='拏' then 'N'
     when @crs>='嘸' then 'M'
     when @crs>='垃' then 'L'
     when @crs>='咔' then 'K'
     when @crs>='丌' then 'J'
     when @crs>='铪' then 'H'
     when @crs>='旮' then 'G'
     when @crs>='发' then 'F'
     when @crs>='妸' then 'E'
     when @crs>='咑' then 'D'
     when @crs>='嚓' then 'C'
     when @crs>='八' then 'B'
     when @crs>='吖' then 'A'
     else  @crs  end+@result
    end 
    return(@result) 
end