Get the stored procedure for the phonetic Word header

Source: Internet
Author: User
Stored procedure | pinyin

-- =============================================
--Create scalar function (Nwgetpyfirst)
-- =============================================
IF EXISTS (SELECT *
From sysobjects
WHERE name = N ' Nwgetpyfirst ')
DROP FUNCTION Nwgetpyfirst
Go

CREATE FUNCTION Nwgetpyfirst
(@str varchar (500) = ')
RETURNS varchar (500)
As
BEGIN
Declare @strlen int,
@return varchar (500),
@ii int,
@c char (1),
@chn nchar (1)
--//Initialization variables
Declare @pytable Table (
CHN Char (2) COLLATE chinese_prc_cs_as not NULL,
Py char (1) COLLATE chinese_prc_cs_as NULL,
PRIMARY KEY (CHN)
)
INSERT into @pytable values (' acridine ', ' A ')
INSERT into @pytable values (' Eight ', ' B ')
INSERT into @pytable values (' Cha ', ' C ')
INSERT into @pytable values (' 咑 ', ' D ')
INSERT into @pytable values (' 妸 ', ' E ')
INSERT into @pytable values (' Hair ', ' F ')
INSERT into @pytable values (' There ', ' G ')
INSERT into @pytable values (' hafnium ', ' H ')
INSERT into @pytable values (' No ', ' I ')
--insert into @pytable values (' No ', ' J ')
INSERT into @pytable values (' ka ', ' K ')
INSERT into @pytable values (' garbage ', ' L ')
INSERT into @pytable values (' 嘸 ', ' M ')
INSERT into @pytable values (' 拏 ', ' N ')
INSERT into @pytable values (' Oh ', ' O ')
INSERT into @pytable values (' 妑 ', ' P ')
INSERT into @pytable values (' Seven ', ' Q ')
INSERT into @pytable values (' 呥 ', ' R ')
INSERT into @pytable values (' sa ', ' S ')
INSERT into @pytable values (' He ', ' T ')
INSERT into @pytable values (' 屲 ', ' U ')
--insert into @pytable values (' 屲 ', ' V ')
--insert into @pytable values (' 屲 ', ' W ')
INSERT into @pytable values (' XI ', ' X ')
INSERT into @pytable values (' ya ', ' Y ')
INSERT into @pytable values (' 帀 ', ' Z ')

Select @strlen = Len (@str), @return = ', @ii = 0
--//loops the entire string, replacing Chinese characters with the first letter of Pinyin
While @ii < @strlen
Begin
Select @ii = @ii + 1, @chn = substring (@str, @ii, 1)
If @chn > ' z '--//retrieve the input string with Chinese characters
SELECT @c = max (py)
From @pytable
where CHN <= @chn
Else
Set @c= @chn

Set @return = @return +@c
End
Return @return
End
Go

-- =============================================
--Example to execute function
-- =============================================
SELECT dbo. Nwgetpyfirst (' Dream Country '), dbo. Nwgetpyfirst (' Noctwolf share source '), dbo. Nwgetpyfirst (")"
Go



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.