• SqlServer的汉字转拼音码的函数


    代码
    --
    --
     Definition for user-defined function f_GetPy : 
    --
    GO
    create   function   [dbo].f_GetPy(@str   nvarchar(4000)) 
    returns   nvarchar(4000
    as 
    begin 
    declare   @strlen   int,@re   nvarchar(4000
    declare   @t   table(chr   nchar(1)   collate   Chinese_PRC_CI_AS,letter   nchar(1)) 
    insert   into   @t(chr,letter) 
        
    select   '吖 '''   union   all   select   '八 '''   union   all 
        
    select   '嚓 '''   union   all   select   '咑 '''   union   all 
        
    select   '妸 '''   union   all   select   '发 '''   union   all 
        
    select   '旮 '''   union   all   select   '铪 '''   union   all 
        
    select   '丌 '''   union   all   select   '咔 '''   union   all 
        
    select   '垃 '''   union   all   select   '嘸 '''   union   all 
        
    select   '拏 '''   union   all   select   '噢 '''   union   all 
        
    select   '妑 '''   union   all   select   '七 '''   union   all 
        
    select   '呥 '''   union   all   select   '仨 '''   union   all 
        
    select   '他 '''   union   all   select   '屲 '''   union   all 
        
    select   '夕 '''   union   all   select   '丫 '''   union   all 
        
    select   '帀 ''' 
        
    select   @strlen=len(@str),@re= ' ' 
        
    while   @strlen> 0 
        
    begin 
            
    select   top   1   @re=letter+@re,@strlen=@strlen-1 
                
    from   @t   a   where   chr <=substring(@str,@strlen,1
                
    order   by   chr   desc 
            
    if   @@rowcount=0 
                
    select   @re=substring(@str,@strlen,1)+@re,@strlen=@strlen-1 
        
    end 
        
    return(@re
    end

    代码
    //用法一
    string sql = string.Format("Name like '%{0}%' or dbo.f_GetPy(Name) like '{0}%' ", goodsName);

    //用法二
    string sql = string.Format(@"Select * from (Select Company_Name from tb_enterprise where Company_Name like '%{1}%' or F_PINYIN(Company_Name) like '%{1}%' ) 
                                             WHERE ROWNUM <= {0} ORDER BY ROWNUM ASC
    ", topCount, name);
  • 相关阅读:
    No EntityManager with actual transaction available for current thread
    vue-router.esm.js?8c4f:16 [vue-router] missing param for named route "magneto.xmqsDx.edit": Expected "id" to be defined的解决办法
    运用equals来比对对象或者是对象集合的removeAll等是需要重写equals和hashCode,IDEA重写equals和hashCode
    本地连接远程rabbitMQ失败
    注解@Column实现实体类到数据库字段的映射以及解决映射过程中的type#[]类型错误
    Navicat激活工具激活方法
    Google浏览器主页被篡改(目标里没有网址)的解决办法--亲测有效
    css----transition的应用,产生动画效果。
    电信NBIOT 6
    电信NBIOT 5
  • 原文地址:https://www.cnblogs.com/kokoliu/p/1657784.html
Copyright © 2020-2023  润新知