SQL Server gets pinyin initials for Chinese characters

Source: Internet
Author: User

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

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.