According to the initials of Chinese characters, find relevant records in the table. For example, enter "zgyh", you can find all the "Bank of China" records.
Chinese characters
According to the initials of Chinese characters, to find relevant records in the table, how to achieve? For example, enter "Zgyh", you can find all the "Bank of China" records.
if exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ F_GETPY] and Xtype in (n ' FN ', n ' IF ', n ' TF '))
Drop function [dbo]. [F_getpy]
Go
--Create phonetic function
Create function f_getpy (@Str nvarchar (400))
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 @t Select ' Acridine ', ' A ' union ALL select ' Eight ', ' B '
UNION ALL select ' Cha ', ' C ' union ALL Select ' 咑 ', ' D '
UNION ALL SELECT ' 妸 ', ' E ' union ALL Select ' Hair ', ' F '
UNION ALL SELECT ' There ', ' G ' union ALL Select ' Hafnium ', ' H '
UNION ALL SELECT ' No ', ' J ' union ALL select ' Ka ', ' K '
UNION ALL select ' garbage ', ' L ' union ALL Select ' 嘸 ', ' M '
UNION ALL SELECT ' 拏 ', ' N ' union ALL select ' Oh ', ' O '
UNION ALL SELECT ' 妑 ', ' P ' union ALL select ' Seven ', ' Q '
UNION ALL SELECT ' 呥 ', ' R ' union ALL SELECT ' sa ', ' S '
UNION ALL SELECT ' he ', ' T ' union ALL Select ' 屲 ', ' W '
UNION ALL SELECT ' XI ', ' X ' union ALL Select ' Ya ', ' Y '
UNION ALL SELECT ' 帀 ', ' Z '
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
Go
--Test
Select Dbo.f_getpy (' Dongguan ') as Dongguan, dbo.f_getpy (' C people of AB ') as Chinese
--After the query, you can call the above function to realize the Chinese character fuzzy query
SELECT * FROM table where dbo.f_getpy (field) = ' Zgyh '
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.