Conversion: converting Chinese characters to PinYin codes (SQL Server)
Source: Internet
Author: User
Create Function Fun_getpy ( @ Str Nvarchar ( 4000 ))
Returns Nvarchar ( 4000 )
As
Begin
Declare @ Word Nchar ( 1 ), @ Py Nvarchar ( 4000 )
Set @ Py = ''
While Len ( @ Str ) > 0
Begin
Set @ Word = Left ( @ Str , 1 )
-- If it is not a Chinese character, the original character is returned.
Set @ Py = @ Py + ( Case When Unicode ( @ Word ) Between 19968 And 19968 + 20901
Then ( Select Top 1 PY From (
Select ' A ' As PY, n ' Bytes ' As Word
Union All Select ' B ' , N ' Book '
Union All Select ' C ' , N ' Bytes '
Union All Select ' D ' , N ' Bytes '
Union All Select ' E ' , N ' Bytes '
Union All Select ' F ' , N ' Bytes '
Union All Select ' G ' , N ' Bytes '
Union All Select ' H ' , N ' Bytes '
Union All Select ' J ' , N ' Bytes '
Union All Select ' K ' , N ' Bytes '
Union All Select ' L ' , N ' Bytes '
Union All Select ' M ' , N ' Bytes '
Union All Select ' N ' , N ' Bytes '
Union All Select ' O ' , N ' Bytes '
Union All Select ' P ' , N ' Exposure '
Union All Select ' Q ' , N ' Bytes '
Union All Select ' R ' , N ' Bytes '
Union All Select ' S ' , N ' Bytes '
Union All Select ' T ' , N ' Bytes '
Union All Select ' W ' , N ' Bytes '
Union All Select ' X ' , N ' Bytes '
Union All Select ' Y ' , N ' Bytes '
Union All Select ' Z ' , N ' Bytes '
) T
Where Word > = @ Word Collate chinese_prc_cs_as_ks_ws
Order By PY ASC ) Else @ Word End )
Set @ Str = Right ( @ Str , Len ( @ Str ) - 1 )
End
Return @ Py
End
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.