惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
Recent Announcements
Recent Announcements
雷峰网
雷峰网
The GitHub Blog
The GitHub Blog
罗磊的独立博客
月光博客
月光博客
J
Java Code Geeks
A
About on SuperTechFans
Microsoft Security Blog
Microsoft Security Blog
D
Docker
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
F
Fortinet All Blogs
U
Unit 42
C
Check Point Blog
Martin Fowler
Martin Fowler
有赞技术团队
有赞技术团队
博客园 - 叶小钗
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
酷 壳 – CoolShell
酷 壳 – CoolShell
Blog — PlanetScale
Blog — PlanetScale
大猫的无限游戏
大猫的无限游戏
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
阮一峰的网络日志
阮一峰的网络日志
MyScale Blog
MyScale Blog

博客园 - 唐朝程序员

推荐一个winform 界面交互类库转 DBCC SHOWCONTIG、DBCC DBREINDEX。 SQL Server2005索引碎片分析和解决方法 some things 微软自带的防反编译工具dotfuscator.exe的使用 在HttpModule中使用gzip,deflate协议对aspx页面进行压缩(转) SQL查询重复数据和清除重复数据 lucene 笔记 windows系统事件查询 2010考研冲刺必备 2010公务员考试必备资料 url重写适用html为伪静态后真实的html无法访问的解决方法 SQL的 优化 (某篇的精简版) SQL 优化 (某篇的精简版) U影资源网原域名被封了,现在叫狐库网,启用了新的域名 vs2008 下载地址以及正式版序列号 Windows XP和Office2003通过正版验证,免去黑屏之忧 NOKIA诺基亚PC套件在2003系统上的安装方法 在.net 2.0 中使用ftp
SqlServer的汉字转拼音码的函数
唐朝程序员 · 2010-01-27 · via 博客园 - 唐朝程序员

代码

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