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