详解SQL Server 如何得到汉字的声母
在SQL中创建用户自定义拼音函数: Qkci#y,a
create function f_GetPy(@Str nvarchar(400)) *As0AJ
returns nvarchar(4000) 3WtgZ'<
as /k'*U5Zk:>
begin ] ax3A
declare @strlen int,@re nvarchar(4000) efk;6/Tp
declare @t table(chr nchar(1) collate Chinese_PRC_CI_AS,letter nchar(1)) ;=;1-b08xz
insert @t select '吖','A' union all select '八','B' q!$YgQI T
union all select '嚓','C' union all select '咑','D' a(,jF>vL>
union all select '妸','E' union all select '发','F' `i|(@Axz:
union all select '旮','G' union all select '铪','H' |^z&Y[P2*
union all select '丌','J' union all select '咔','K' pz YgXu
union all select '垃','L' union all select '嘸','M' k_*`m kq
union all select '拏','N' union all select '噢','O' xxlFgXM=
union all select '妑','P' union all select '七','Q' ?Cui"EDu
union all select '呥','R' union all select '仨','S' 5wYA&^
union all select '他','T' union all select '屲','W' E1OVLieU
union all select '夕','X' union all select '丫','Y' U(7*{ZV!*
union all select '帀','Z' kiG06t0-I
x @ZH.]&
select @strlen=len(@str),@re='' u3>{[#Nw
while @strlen>0 xMYU#}nD
begin 20e|4J&^
select top 1 @re=letter+@re,@strlen=@strlen-1 AJa]${Lx}H
from @t a where chr<=substring(@str,@strlen,1) llhAU\5:Y
order by chr desc w:Y:|=wb0
if @@rowcount=0 lqC":>
select @re=substring(@str,@strlen,1)+@re,@strlen=@strlen-1 @ ( 7>
end K R_vqW
return(@re) <cNK-Rf*
end G-~jn~e
go n4XiERg
--测试 w{%c<tb
select dbo.f_GetPy('东莞市') as 东莞市,dbo.f_GetPy('ab中c国人') as 中国人 bI0{hR . w
;A},FAj^\
--以后查询的时候,就可以调用上面的函数来实现汉字模糊查询 p-uP~X17k
w|(N-Xv,
select * from 表 where dbo.f_getpy(字段)='zgyh'