Create Function f_getpy (@ STR nvarchar (4000 ))
Returns nvarchar (4000)
As
Begin
Declare @ strlen int, @ Re nvarchar (4000)
Declare @ t table (CHR nchar (1) Collate chinese_prc_ci_as, letter nchar (1 ))
Insert into @ T (CHR, letter)
Select 'ay', 'A' Union all select '8', 'B' Union all
Select 'accept', 'C' Union all select 'accept', 'D' Union all
Select 'hangzhou', 'E' Union all select 'hangzhou', 'F' Union all
Select 'hangzhou', 'G' Union all select 'haid', 'H' Union all
Select ', 'J' Union all select 'hour', 'K' Union all
Select 'hangzhou', 'L' Union all select 'hangzhou', 'M' Union all
Select 'hour', 'n' Union all select 'ou', 'O' Union all
Select 'hangzhou', 'P' Union all select '7', 'q' Union all
Select 'hour', 'R' Union all select 'hour', 's' Union all
Select 'others', 't'union all select 'hour', 'w' Union all
Select 'Xi ', 'x' Union all select 'ya', 'y' Union all
Select 'running', 'Z'
Select @ strlen = Len (@ Str), @ Re =''
While @ strlen> 0
Begin
Select top 1 @ Re = letter + @ Re, @ strlen = @ strlen-1
From @ t a where CHR <= substring (@ STR, @ strlen, 1)
Order by CHR DESC
If @ rowcount = 0
Select @ Re = substring (@ STR, @ strlen, 1) + @ Re, @ strlen = @ strlen-1
End
Return (@ Re)
End
Go
-- Call
Select * From ILS where DBO. f_getpy (name) = 'yml'
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.