directly executes the function below, passing in the corresponding parameters in the background to query the data
Create function f_getpy (@str nvarchar (4000)) 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 into @t (chr,letter) Select ' Acridine ', ' A ' union ALL select ' Eight ', ' B ' union ALL Select ' Cha ', ' C ' union ALL Select ' Otah ', ' D ' union ALL Select ' Ehegan ', ' E ' union ALL Select ' Send ', ' F ' union ALL Select ' Xu ', ' G ' UNION ALL SELECT ' Hafnium ', ' H ' union ALL Select ' not ', ' J ' union ALL select ' Ka ', ' K ' union All select ' Junk ', ' L ' union ALL Select ' 嘸 ', ' M ' union ALL Select ' Hallasan ', ' N ' union ALL Sele CT ' Oh ', ' O ' union ALL Select ' 妑 ', ' P ' union ALL select ' Seven ', ' Q ' union ALL Select ' 呥 ', ' R ' UNION ALL Select ' Three ', ' S ' union ALL Select ' he ', ' T ' union ALL Select ' 屲 ', ' W ' Unio n All Select ' Yubari', ' X ' union ALL Select ' Ya ', ' Y ' union ALL Select ' as ', ' Z ' select @strlen =len (@str), @re = ' While @strlen > 0 begin SELECT top 1 @[email protected],@[email protected] From @t a where CHR <=substring (@str, @strlen, 1) Order BY CHR desc if @ @rowcount =0 Select @re =substring (@str, @strlen, 1) [email protected],@[email protected] End return (@re) E ND---Query---select * FROM [Pactinfo]where Left (Dbo.f_getpy (Pactname), 1) = ' Z '
SQL Server queries data based on pinyin