function | Chinese Character | string
/*--obtains the first letter of Chinese character string--*/
if exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ FGETPY] and Xtype in (n ' FN ', n ' IF ', n ' TF '))
Drop function [dbo]. [Fgetpy]
Go
--Create phonetic function
Create function fgetpy (@Str varchar (500) = ')
Returns varchar (500)
As
begin--function Implementation begins
declare @strlen int, @return varchar, @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--while Cycle Start
Select @ii = @ii +1,@n=63, @chn =substring (@str, @ii, 1)
If @chn > ' z '--if start
--There is only one SELECT statement, the principle of "string sorting and ASCII code table":
Select @n = @n +1,@c =--★★★select★★★
Case CHN--case Start
When @chn then char (@n)--case Branch
else @c--case Branch
End--case Ends
From (--★★★from★★★
Select top of * FROM (
Select CHN = ' Acridine '
UNION ALL select ' Eight '
UNION ALL select ' Cha '
UNION ALL SELECT ' 咑 '
UNION ALL SELECT ' 妸 '
UNION ALL SELECT ' Send '
UNION ALL SELECT ' There '
UNION ALL SELECT ' Hafnium '
UNION ALL SELECT ' No '--because have no ' i '
UNION ALL SELECT ' No '
UNION ALL select ' Ka '
UNION ALL select ' garbage '
UNION ALL SELECT ' 嘸 '
UNION ALL SELECT ' 拏 '
UNION ALL select ' Oh '
UNION ALL SELECT ' 妑 '
UNION ALL select ' Seven '
UNION ALL SELECT ' 呥 '
UNION ALL select ' sa '
UNION ALL SELECT ' he '
UNION ALL SELECT ' 屲 '--no ' u '
UNION ALL SELECT ' 屲 '--no ' V '
UNION ALL SELECT ' 屲 '
UNION ALL select ' XI '
UNION ALL select ' Ya '
UNION ALL SELECT ' 帀 '
UNION ALL Select @chn) as a
ORDER BY CHN COLLATE Chinese_prc_ci_as
) as B
else--if the corresponding else
Set @c= @chn
--if End
Set @return = @return +@c
End--while Loop End
Return (@return)
End of end--function implementation
Go
--Test
Select Dbo.fgetpy (' Wei Baoquan ') as name Pinyin, dbo.fgetpy (' C people in AB ') as Chinese
Select Dbo.fgetpy (' Liu Ziliang ') as name Pinyin, dbo.fgetpy (' C people in AB ') as Chinese
Select Dbo.fgetpy (' Wu-too ') as name Pinyin, Dbo.fgetpy (' C Chinese ') as China
Select Dbo.fgetpy (' northeast ') as name Pinyin, dbo.fgetpy (' C people in AB ') as Chinese
Select Dbo.fgetpy (' Wang Dahai VIII ') as Wang Dahai eight ya, dbo.fgetpy (' service map ') as service map
--Removing phonetic functions
Drop function Fgetpy