sql server自动生成拼音首字母的函数

时间:2024-01-25 15:27:19 

建立一个查询,执行下面的语句生成函数fn_GetPy


--生成拼音首码
CREATE function fn_GetPy(@str nvarchar(4000))
returns nvarchar(4000)
--WITH ENCRYPTION
as
begin
declare @intLen int
declare @strRet nvarchar(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) >= '丫' then 'Y'
when substring(@str,@intLen,1) >= '夕' then 'X'
when substring(@str,@intLen,1) >= '屲' then 'W'
when substring(@str,@intLen,1) >= '他' then 'T'
when substring(@str,@intLen,1) >= '仨' then 'S'
when substring(@str,@intLen,1) >= '呥' then 'R'
when substring(@str,@intLen,1) >= '七' then 'Q'
when substring(@str,@intLen,1) >= '妑' then 'P'
when substring(@str,@intLen,1) >= '噢' then 'O'
when substring(@str,@intLen,1) >= '拏' then 'N'
when substring(@str,@intLen,1) >= '嘸' then 'M'
when substring(@str,@intLen,1) >= '垃' then 'L'
when substring(@str,@intLen,1) >= '咔' then 'K'
when substring(@str,@intLen,1) >= '丌' then 'J'
when substring(@str,@intLen,1) >= '铪' then 'H'
when substring(@str,@intLen,1) >= '旮' then 'G'
when substring(@str,@intLen,1) >= '发' then 'F'
when substring(@str,@intLen,1) >= '妸' then 'E'
when substring(@str,@intLen,1) >= '咑' then 'D'
when substring(@str,@intLen,1) >= '嚓' then 'C'
when substring(@str,@intLen,1) >= '八' then 'B'
when substring(@str,@intLen,1) >= '吖' then 'A'
else rtrim(ltrim(substring(@str,@intLen,1)))
end
--对于汉字特殊字符,不生成拼音码
if (ascii(@temp)>127) set @temp = ''
--对于英文中小括号,不生成拼音码
if @temp = '(' or @temp = ')' set @temp = ''
select @strRet = @temp + @strRet
set @intLen = @intLen - 1
end
return lower(@strRet)
end


。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

测试:
SELECT Product_ID , dbo.fn_GetPy(Product_Name) AS pymc
FROM dbo.T_Product

标签:自动生成,拼音首字母
0
投稿

猜你喜欢

  • Python实现通过文件路径获取文件hash值的方法

    2023-10-27 21:41:20
  • python中datetime模块中strftime/strptime函数的使用

    2023-11-15 15:02:46
  • vue实现登录拦截

    2024-04-30 10:25:20
  • Linux系统(X64)安装Oracle11g完整安装图文教程另附基本操作

    2023-07-07 08:25:36
  • 教你快速掌握数据库查询优化的实用技巧

    2008-11-28 15:10:00
  • 深入理解Python单元测试unittest的使用示例

    2022-03-18 04:51:00
  • pycharm无法安装第三方库的问题及解决方法以scrapy为例(图解)

    2022-11-01 20:53:28
  • Python中性能分析利器pyinstrument详细讲解

    2021-02-15 10:46:51
  • golang爬虫colly 发送post请求

    2024-02-05 09:35:03
  • python利用标准库如何获取本地IP示例详解

    2021-10-17 07:46:07
  • XHTML1.0与HTML兼容指引16条[译]

    2009-06-10 14:45:00
  • Python高效编程技巧

    2023-08-19 17:29:56
  • Python环境配置实现pip加速过程解析

    2022-09-23 12:42:37
  • python去掉空格的一些常用方式

    2022-02-10 04:45:34
  • python实现基于SVM手写数字识别功能

    2021-10-03 12:33:41
  • php返回相对时间(如:20分钟前,3天前)的方法

    2023-10-26 11:20:38
  • 解决SQLServer最大流水号的两个好方法

    2009-01-13 14:15:00
  • MySQL Proxy应用入门(1)--安装MySQL Proxy

    2011-03-08 09:50:00
  • PHP入门速成(3)

    2023-11-20 18:48:03
  • Python海龟turtle基础知识大全以及画图集合实例

    2022-05-01 08:12:34
  • asp之家 网络编程 m.aspxhome.com