代码
--
--
 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);

 

 

相关文章:

  • 2022-12-23
  • 2021-10-12
  • 2021-08-01
  • 2021-12-28
  • 2021-11-24
  • 2021-05-19
  • 2022-02-12
猜你喜欢
  • 2022-12-23
  • 2021-11-04
  • 2021-10-09
  • 2022-03-05
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
相关资源
相似解决方案