200分急求按拼音简写在数据库中查询汉字(200分)

  • 主题发起人 主题发起人 Kaster
  • 开始时间 开始时间
K

Kaster

Unregistered / Unconfirmed
GUEST, unregistred user!
我用了一个排序函数,但是查询的时候同姓的只能查到三个字的,两个字的查不到,这是我的排序函数,高手帮忙看看哪里有问题,如果回答的好,所有分送出!
ALTER function fun_getPY(@str nvarchar(4000))
returns nvarchar(4000)
as
begin
declare @word nchar(1),@PY nvarchar(4000),@i int
set @PY=''
set @i=1
while (substring(@str,@i,1)<>'' or @i<=len(@str))
begin
set @word=substring(@str,@i,1)
--如果非汉字字符,返回原字符
set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901
then (select top 1 PY from (
select 'A' as PY,N'驁' as word
union all select 'B',N'簿'
union all select 'C',N'錯'
union all select 'D',N'鵽'
union all select 'E',N'樲'
union all select 'F',N'鰒'
union all select 'G',N'腂'
union all select 'H',N'夻'
union all select 'J',N'攈'
union all select 'K',N'穒'
union all select 'L',N'鱳'
union all select 'M',N'旀'
union all select 'N',N'桛'
union all select 'O',N'漚'
union all select 'P',N'曝'
union all select 'Q',N'囕'
union all select 'R',N'鶸'
union all select 'S',N'蜶'
union all select 'T',N'籜'
union all select 'W',N'鶩'
union all select 'X',N'鑂'
union all select 'Y',N'韻'
union all select 'Z',N'咗'
) T
where word>=@word collate Chinese_PRC_CS_AS_KS_WS
order by PY ASC) else @word end)
set @i=@i+1
end

if @PY<>'' select @PY=substring(@PY,1,1)

return @PY
end
 
实用技术顶
 
试试这个是不是你想要的

function GetPYIndexChar(hzchar:string):char;
begin
case WORD(hzchar[1]) shl 8 + WORD(hzchar[2]) of
$B0A1..$B0C4 : result := 'A';
$B0C5..$B2C0 : result := 'B';
$B2C1..$B4ED : result := 'C';
$B4EE..$B6E9 : result := 'D';
$B6EA..$B7A1 : result := 'E';
$B7A2..$B8C0 : result := 'F';
$B8C1..$B9FD : result := 'G';
$B9FE..$BBF6 : result := 'H';
$BBF7..$BFA5 : result := 'J';
$BFA6..$C0AB : result := 'K';
$C0AC..$C2E7 : result := 'L';
$C2E8..$C4C2 : result := 'M';
$C4C3..$C5B5 : result := 'N';
$C5B6..$C5BD : result := 'O';
$C5BE..$C6D9 : result := 'P';
$C6DA..$C8BA : result := 'Q';
$C8BB..$C8F5 : result := 'R';
$C8F6..$CBF9 : result := 'S';
$CBFA..$CDD9 : result := 'T';
$CDDA..$CEF3 : result := 'W';
$CEF4..$D1B8 : result := 'X';
$D1B9..$D4D0 : result := 'Y';
$D4D1..$D7F9 : result := 'Z';
else
result := char(0);
end;
end;

function SearchByPYIndexStr(SourceStrs:TStrings;PYIndexStr:string):string;label NotFound;
var
i, j :integer;
hzchar :string;
begin
for i:=0 to SourceStrs.Count-1 do //源名字
begin
for j:=1 to Length(PYIndexStr) do //拼音简写
begin
hzchar:=SourceStrs[2*j-1]+ SourceStrs[2*j];
if (PYIndexStr[j]<>'?') and (UpperCase(PYIndexStr[j]) <>GetPYIndexChar(hzchar)) then
goto NotFound;
end;
if result='' then result := SourceStrs
else result := result + Char(13) + SourceStrs;
NotFound:
end;
end;
 
谢谢两位,已经搞定![:)]
 
后退
顶部