Write scalar functions in SQL generate uppercase Pinyin initials

Source: Internet
Author: User
Tags scalar

Use [Stockmanagesystemv2]go/** * * * object:userdefinedfunction [dbo].    [PinYin] Script date:2016-08-07 11:19:20 * * * * **/SET ansi_nulls ongoset quoted_identifier ongoalter FUNCTION [dbo]. [PinYin] (@STR NVARCHAR (4000)) RETURNS NVARCHAR (4000) as BEGIN DECLARE @INTLEN INT; DECLARE @STRRET NVARCHAR (4000); DECLARE @TEMP NVARCHAR ( -); SET @INTLEN=LEN (@STR); SET @STRRET="'; While @INTLEN>0BEGIN SET @TEMP="'; SELECT @TEMP= case when SUBSTRING (@STR, @INTLEN,1) >='as'Then'Z'When SUBSTRING (@STR, @INTLEN,1) >='ya'Then'Y'When SUBSTRING (@STR, @INTLEN,1) >='XI'Then'X'When SUBSTRING (@STR, @INTLEN,1) >='屲'Then'W'When SUBSTRING (@STR, @INTLEN,1) >='his'Then'T'When SUBSTRING (@STR, @INTLEN,1) >='SA'Then'S'When SUBSTRING (@STR, @INTLEN,1) >='呥'Then'R'When SUBSTRING (@STR, @INTLEN,1) >='Seven'Then'Q'When SUBSTRING (@STR, @INTLEN,1) >='妑'Then'P'When SUBSTRING (@STR, @INTLEN,1) >='Oh'Then'O'When SUBSTRING (@STR, @INTLEN,1) >='Hallasan'Then'N'When SUBSTRING (@STR, @INTLEN,1) >='嘸'Then'M'When SUBSTRING (@STR, @INTLEN,1) >=' Garbage'Then'L'When SUBSTRING (@STR, @INTLEN,1) >='ka'Then'K'When SUBSTRING (@STR, @INTLEN,1) >=' not'Then'J'When SUBSTRING (@STR, @INTLEN,1) >='hafnium'Then'H'When SUBSTRING (@STR, @INTLEN,1) >='Xu'Then'G'When SUBSTRING (@STR, @INTLEN,1) >='Hair'Then'F'When SUBSTRING (@STR, @INTLEN,1) >='Ehegan'Then'E'When SUBSTRING (@STR, @INTLEN,1) >='Otah'Then'D'When SUBSTRING (@STR, @INTLEN,1) >='Cha'Then'C'When SUBSTRING (@STR, @INTLEN,1) >='Eight'Then'B'When SUBSTRING (@STR, @INTLEN,1) >='Acridine'Then'A'ELSE RTRIM (LTRIM (SUBSTRING (@STR, @INTLEN,1)) END; --for kanji special characters, do not generate phonetic code IF (ASCII (@TEMP)>127) SET @TEMP="'; --for English small brackets, do not generate phonetic code IF @TEMP='('OR @TEMP=')'SET @TEMP="'; SELECT @STRRET= @TEMP +@STRRET; SET @INTLEN= @INTLEN-1;        END;    RETURN @STRRET; END;

Write scalar functions in SQL generate uppercase Pinyin initials

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.