SQL SERVER functions to get phonetic abbreviations

Source: Internet
Author: User

Function:

/*To create a phonetic first letter function*/ Create function [dbo].[Fn_chinesetospell](@strChinese varchar( -)="') returns varchar( -)  as begin /*function Implementation begins*/      Declare @strLen int,@return varchar( -),@i int      Declare @n int,@c Char(1),@chn nchar(1)       Select @strLen=Len(@strChinese),@return="',@i=0       while @i<@strLen      begin /*While Loop starts*/             Select @i=@i+1,@n= the,@chn=substring(@strChinese,@i,1)              if @chn>'Z'/*principle: "String sorting and ASCII code table"*/                                 Select @n = @n +1,@c = CaseChn when @chn  Then Char(@n)Else @c End  from(Select Top  - *  from(SelectChn= 'Acridine' Union  All Select 'Eight' Union  All Select 'Cha' Union  All Select 'Otah' Union  All Select 'Ehegan'  Union  All Select 'Hair'  Union  All Select 'Xu'  Union  All Select 'hafnium'  Union  All Select ' not' /*because have no ' i '*/ Union  All Select ' not' Union  All Select 'ka' Union  All Select ' Garbage' Union  All Select '嘸' Union  All Select 'Hallasan' Union  All Select 'Oh' Union  All Select '妑' Union  All Select 'Seven' Union  All Select '呥' Union  All Select 'SA' Union  All Select 'his' Union  All Select '屲' /*no ' u '*/ Union  All Select '屲' /*No ' V '*/ Union  All Select '屲' Union  All Select 'XI' Union  All Select 'ya' Union  All Select 'as' Union  All Select @chn) asAOrder  byCHN COLLATE chinese_prc_ci_as) asbElse                 Set @c=@chn             Set @return=@return+@c       End /*While Loop ends*/       return(@return)  End /*End of function implementation*/

How to use:

UPDATE SET = Dbo.fn_chinesetospell (Name)

SQL SERVER functions to get phonetic abbreviations

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.