The function passes in a string and returns the data: if it is a kanji character, the first letter of the character is returned, and if it is a non-kanji character, it returns itself.
Second, the use of the knowledge Point: The Chinese character corresponding to the Unicode value, the Chinese character collation rules.
Third, database functions:
CREATE FUNCTION Getinitialletter (@ChineseString NVARCHAR (4000)) RETURNS NVARCHAR (4000) Asbegin DECLARE @ SingleCharacter NCHAR (1), @ReturnString NVARCHAR (4000) SET @ReturnString = "while LEN (@ChineseString) >0 begin--the single character set @SingleCharacter = Left (@ChineseString, 1)----kanji characters, return characters corresponding to the first letter, non-kanji characters, and return the original character if (UNICODE (@ SingleCharacter) between 19968 and 19968+20901) SET @ReturnString = @ReturnString + (select TOP 1 py from (SELECT ' A ' as PY, N ' ao ' as chinesecharacters union ALL SELECT ' B ', n ' book ' union ALL Select ' C ', n ' wrong ' union ALL Select ' D ', n ' 鵽 ' union ALL SELECT ' E ', n ' 樲 ' union ALL Select ' F ', n ' leiognathi ' union ALL Select ' G ', n ' hiker ' union ALL Select ' H ', n ' inceѕt ' union ALL Select ' J ', n ' 攈 ' UNION ALL Select ' K ', n ' 穒 ' union ALL Select ' L ', n ' 鱳 ' union ALL Select ' M ', n ' temperature ' union ALL SELECT ' n ', n ' 桛 ' union ALL Select ' O ', n ' retting ' UN ION all Select ' P ', n ' exposure ' UNION ALL SELECT ' Q ', n ' 囕 ' union ALL Selects ' R ', n ' 鶸 ' union ALL Select ' S ', n ' 蜶 ' union ALL select ' T ' , N ' sheaths ' union ALL Select ' W ', n ' Mo ' union ALL select ' X ', n ' 鑂 ' union ALL SELECT 'Y ', n ' rhyme ' UNION all SELECT ' Z ', n ' off ') spellingtable where chinesecharacters > = @SingleCharacter COLLATE chinese_prc_cs_as _ks_ws ORDER by PY ASC) Elseset @ReturnString = @ReturnString + @SingleCharacter SET @ChineseString = right (@ChineseString, LEN (@ChineseString)-1) END RETURN @ReturnString Endgo
SELECT dbo. Getinitialletter (' refueling 2018 ')
return: JY2018
SQL Server gets pinyin initials for Chinese characters