How to realize the first letters of Chinese character pinyin through UDF?

xiaoxiao2021-03-06  102

- // The following Stored Procedure is the first letter IF exists (Select * from dbo.sysObjects where id string) (N '[dbo]. [Udf_getfirst_py]') and xtype in (n'fn ', N'IF ', N'TF')) drop function [dbo]. [udf_GetFirst_Py] GOCreate function udf_GetFirst_Py (@Str varchar (500) = '') returns varchar (500) asbeginDeclare @strlen int, @ return varchar (500) , @ ii intDeclare @n Int, @ c char (1), @ chn nchar (1) - // Initialization variable SELECT @ strlen = LEN (@str), @ Return = ', @ ii = 0 - / / Confirm the input is not empty if @ strlen = 0beginselect @ Return = 'please input - // loop the entire string, replace the Chinese characters for the first letters of the Pinyin While @ii <@strlenbeg ISELECT @ii @ @ ii 1, @ n = 63, @n = Substring (@ Str, @ II, 1) if @chn> 'z' - // Retrieving the input string with Chinese characters Select @ n = @ n 1, @ c = case chn when @n thenchar (@n) Else @c endfrom (select top 27 * from (select chn = 'union allselect' eight 'union allselect' 'union allselect' 咑 'union allselect 'E' union allselect 'hair' union allselect 'ga' union allselect 'hafnium' union allselect 'Ji' union allselect 'Ji' union allselect 'cracking' union allselect 'refuse' union allselect 'Chum' union allselect 'take' union allselect '' Un ion allselect 'Pa' union allselect 'seven' union allselect 'Ran' union allselect 'Sa' union allselect 'he' union allselect 'Wa' union allselect 'Wa' union allselect 'Wa' union allselect 'Xi' union allselect 'Ah' Union allselect '帀' union allselect @chn) as aorder by chn collateChinese_prc_ci_as) as Belse Set @

C = @ chnset @ Return = @ Return @ CENDRETURN (@return) endgo - // Test Select dbo.udf_getfirst_py ('Shanghai'), dbo.udf_getfirst_py ('AB The same TEST pronunciation'), dbo.udf_getfirst_py ('' ) "Wang Ting" Wrote in Message

转载请注明原文地址:https://www.9cbs.com/read-101858.html

New Post(0)