/* -- Obtain the first letter of a Chinese character string According to the strong posts, I changed the two strong functions into a function. It can be applied to the query of mnemonic codes. Author: zhujian --*/ 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 a pinyin Function 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) If @ CHN> 'Z' Select @ n = @ n + 1 , @ C = case CHN when @ CHN then Char (@ n) else @ C end From ( Select top 27 * from ( Select CHN = 'ay' Union all select '8' Union all select 'signature' Union all select 'signature' Union all select 'signature' Union all select 'output' Union all select 'signature' Union all select 'haid' Union all select '-- because have no' I' Union all select 'stop' Union all select 'signature' Union all select 'signature' Union all select 'signature' Union all select 'signature' Union all select 'ou' Union all select 'signature' Union all select '7' Union all select 'signature' Union all select 'signature' Union all select 'others' Union all select 'hour' -- no 'U' Union all select 'hour' -- no 'V' Union all select 'signature' Union all select 'Xi' Union all select 'ya' Union all select 'signature' Union all select @ CHN) as Order by CHN collate chinese_prc_ci_as ) As B Else set @ C = 'A' Set @ return = @ return + @ C End Return (@ return) End Go -- Test Select DBO. fgetpy ('wei baoguang ') as name pinyin, DBO. fgetpy (' AB 中 C') as Chinese Select DBO. fgetpy ('Liu ziliang ') as name pinyin, DBO. fgetpy (' AB Chinese c ') as Chinese Select DBO. fgetpy ('wu Ta') as name pinyin, DBO. fgetpy ('AB Chinese C') as Chinese Select DBO. fgetpy ('northeast ') as name pinyin, DBO. fgetpy (' AB 中 C') as Chinese -- Delete pinyin Functions Drop function fgetpy |