zoukankan      html  css  js  c++  java
  • SQL 汉字转换成拼音首字母 首字母查

     1 -- =============================================
     2 -- 功能:汉字转换成拼音首字母 首字母查
     3 -- =============================================
     4 ALTER FUNCTION [dbo].[ufn_GetSpellCode](@Str   varchar(500)='')  
     5   returns   varchar(500)  
     6   as 
     7  
     8   begin  
     9       --定义变量
    10       declare   @strlen   int, @return   varchar(500), @ii   int  
    11       declare   @n   int, @c   char(1),@chn   nchar(1)  
    12        --设置初始值
    13       select   @strlen=len(@str),@return='',@ii=0  
    14       set   @ii=0  
    15       --开始循环取出没个字符
    16       while   @ii<@strlen  
    17       begin  
    18           select   @ii=@ii+1,@n=63,@chn=substring(@str,@ii,1)  
    19           if   @chn>'z'  
    20           select   @n   =   @n   +1  ,@c   =   case   chn   when   @chn   then   char(@n)   else   @c   end  
    21           from(  
    22               select   top   27   *  
    23               from(  
    24                   select   chn   =   ''  
    25                   union   all   select   ''  
    26                   union   all   select   ''  
    27                   union   all   select   ''  
    28                   union   all   select   ''  
    29                   union   all   select   ''  
    30                   union   all   select   ''  
    31                   union   all   select   ''  
    32                   union   all   select   '' --because   have   no   'i'  
    33                   union   all   select   ''  
    34                   union   all   select   ''  
    35                   union   all   select   ''  
    36                   union   all   select   ''  
    37                   union   all   select   ''  
    38                   union   all   select   ''  
    39                   union   all   select   ''  
    40                   union   all   select   ''  
    41                   union   all   select   ''  
    42                   union   all   select   ''  
    43                   union   all   select   ''  
    44                   union   all   select   '' --no   'u'  
    45                   union   all   select   '' --no   'v'  
    46                   union   all   select   ''  
    47                   union   all   select   ''  
    48                   union   all   select   ''  
    49                   union   all   select   ''  
    50                   union   all   select   @chn
    51               )   as   a  
    52               order   by   chn   COLLATE   Chinese_PRC_CI_AS    
    53           )   as   b  
    54           else   set   @c=@chn  
    55           set   @return=@return+@c  
    56       end  
    57       return(@return)  
    58   end  
    慎于行,敏于思!GGGGGG
  • 相关阅读:
    C#通过文件头判断图像格式(摘录)
    devenv.exe 应用程序错误
    LINQ TO SQL中的selectMany(转)
    DragDrop registration did not succeed. (摘录)
    API各函数作用简介(转)
    Linq递归用法(摘录)
    (转)逐步为对象集合构建一个通用的按指定属性排序的方法
    何止 Linq 的 Distinct 不给力(转)
    关于sql日志文件
    DES算法的C#实现
  • 原文地址:https://www.cnblogs.com/GarsonZhang/p/3184024.html
Copyright © 2011-2022 走看看