SQL stored procedure

Source: Internet
Author: User

Copy codeThe Code is as follows:
-- Function
CREATE function fn_GetPy (@ str nvarchar (4000 ))
Returns nvarchar (4000)
-- WITH ENCRYPTION
As
Begin
Declare @ intLenint
Declare @ strRetnvarchar (4000)
Declare @ temp nvarchar (100)
Set @ intLen = len (@ str)
Set @ strRet =''
While @ intLen> 0
Begin
Set @ temp =''
Select @ temp = case
When substring (@ str, @ intLen, 1)> = '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)> = 'others'
When substring (@ str, @ intLen, 1)> = 'thens'
When substring (@ str, @ intLen, 1)> = 'duration' then 'R'
When substring (@ str, @ intLen, 1)> = '7' then'q'
When substring (@ str, @ intLen, 1)> = 'ping' then 'P'
When substring (@ str, @ intLen, 1)> = 'ou' then' O'
When substring (@ str, @ intLen, 1)> = 'then' N'
When substring (@ str, @ intLen, 1)> = 'ping' then 'M'
When substring (@ str, @ intLen, 1)> = 'then' L'
When substring (@ str, @ intLen, 1)> = 'then' K'
When substring (@ str, @ intLen, 1)> = '7' then'j'
When substring (@ str, @ intLen, 1)> = 'hagh' then 'H'
When substring (@ str, @ intLen, 1)> = 'then' G'
When substring (@ str, @ intLen, 1)> = 'qout' then 'F'
When substring (@ str, @ intLen, 1)> = 'ping' then'e'
When substring (@ str, @ intLen, 1)> = 'followed 'thend'
When substring (@ str, @ intLen, 1)> = 'ping' then 'C'
When substring (@ str, @ intLen, 1)> = '8' then 'B'
When substring (@ str, @ intLen, 1)> = 'A' then 'A'
Else rtrim (ltrim (substring (@ str, @ intLen, 1 )))
End
-- For special Chinese characters, no pinyin code is generated
If (ascii (@ temp)> 127) set @ temp =''
-- No pinyin code is generated for parentheses.
If @ temp = '(' or @ temp = ') 'set @ temp =''
Select @ strRet = @ temp + @ strRet
Set @ intLen = @ intLen-1
End
Return lower (@ strRet)
End
Go
-- Call
Select dbo. fn_getpy ('zhang san ')
-- Return Value: zs
Answer! : 2:
Stored Procedure
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' comment 'as word
Union all select 'B', n''
Union all select 'C', n' then'
Union all select 'D', N 'region'
Union all select 'E', n' then'
Union all select 'F', n' then'
Union all select 'G', n' then'
Union all select 'h', N 'hour'
Union all select 'J', n' else'
Union all select 'k', n' then'
Union all select 'l', n' then'
Union all select 'M', n' then'
Union all select 'n', n' then'
Union all select 'O', n' then'
Union all select 'P', n' exposure'
Union all select 'Q', n' then'
Union all select 'R', N 'region'
Union all select's ', N 'region'
Union all select 'T', n' then'
Union all select 'w', N 'hangzhou'
Union all select 'x', n' then'
Union all select 'y', n' then'
Union all select 'Z', n' else'
) 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

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.