SQL存储过程获取拼音助记码
作者:C/S框架网|www.cscode.ne  发布日期:2019/07/02 12:34:17
  SQL存储过程获取拼音助记码


SQL Code:


ALTER FUNCTION [dbo].[ufn_GetPY]
(
    
@strChinese VARCHAR(500)='' --中文
  
)
  
RETURNS VARCHAR(500)
  
AS
  
BEGIN
    
/***********************************************************
    
    创建取拼音首字母函数
    
    print dbo.ufn_GetPY('C/S快速开发框架')
    
    ***********************************************************
*/
    
declare @strLen int,@return varchar(500),@i int
    
declare @n int,@c char(1),@chn nchar(1)
    
select @strLen=len(@strChinese),@return='',@i=0
    
while @i<@strLen
    
begin /*while循环开始*/
    
select @i=@i+1,@n=63,@chn=substring(@strChinese,@i,1)
    
if @chn>'z'/*原理:“字符串排序以及ASCII码表”*/
    
select @n = @n +1,@c =case chn when @chn then char(@n) else @c end from(select top 27 * from (select chn = '' union all select '' union all select '' union all select '' union all select '' union all select '' union all select '' union all select '' union all select '' /*because have no 'i'*/ union all select '' union all select '' union all select '' union all select '' union all select '' union all select '' union all select '' union all select '' union all select '' union all select '' union all select '' union all select '' /*no 'u'*/ union all select '' /*no 'v'*/ union all select '' union all select '' union all select '' union all select '' union all select @chn) as a order by chn COLLATE Chinese_PRC_CI_AS ) as b
    
else
    
set @c=@chn
    
set @return=@return+@c
    
end /*while循环结束*/
    
return(@return)
    
    
END /*函数实现结束*/
    
    
//来源:C/S框架网(www.csframework.com) QQ:23404761




上一篇 下一篇