拼音查询

yunzhongfeng 2003-09-13 10:43:22
有好多表,要查询其内容。比如要查询客户名称。我想通过输入一两个字母来查询,请高手给讲一下这需要我重建拼音表吗,是不是就通过一条字母的模糊查询就可以了。请给说下原理及重要步骤。
...全文
81 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
westbulls 2003-09-13
  • 打赏
  • 举报
回复
我觉得你还是应该有一个拼音库表就最好了。要的话,给我你的e-mail
siugwan 2003-09-13
  • 打赏
  • 举报
回复
不错,学习
eastpond 2003-09-13
  • 打赏
  • 举报
回复
学习
zjcxc 元老 2003-09-13
  • 打赏
  • 举报
回复
查询方法:
select * from 表 where dbo.fgetpy(姓名) like '%ZX%'


当然,基于速度上的考虑,最好建立一个拼音字段,在数据录入时调用上面的函数来自动该字段的值,然后在查询的时候用:

select * from 表 wehre 姓名拼音 like '%ZX%'
zjcxc 元老 2003-09-13
  • 打赏
  • 举报
回复
如果你只需要通过首字母来查询,可以直接用下面的函数:
--创建取拼音函数
create function fGetPy(@Str varchar(500)='')
returns varchar(500)
as
begin
declare @strlen int,@return varchar(500),@ii int
declare @n int,@c char(1),@chn nchar(1)

select @strlen=len(@str),@return='',@ii=0
set @ii=0
while @ii<@strlen
begin
select @ii=@ii+1,@n=63,@chn=substring(@str,@ii,1)
select @n = @n +1
,@c = case chn when @chn then char(@n) else @c end
from(
select top 27 * from (
select chn = '吖'
union all select '八'
union all select '嚓'
union all select '咑'
union all select '妸'
union all select '发'
union all select '旮'
union all select '铪'
union all select '丌' --because have no 'i'
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 '屲' --no 'u'
union all select '屲' --no 'v'
union all select '屲'
union all select '夕'
union all select '丫'
union all select '帀'
union all select @chn) as a
order by chn COLLATE Chinese_PRC_CI_AS
) as b
set @return=@return+@c
end
return(@return)
end

go
--测试
select dbo.fgetpy('东莞市') as 东莞市,dbo.fgetpy('中国人') as 中国人

--删除拼音函数
drop function fgetpy
zjcxc 元老 2003-09-13
  • 打赏
  • 举报
回复
如果你要通过完整拼音来查询,需要建一个拼音字段.在数据录入时设置拼音.

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧