目前工作中遇到一个情况,需要将SQL Server中的一个字段提取拼音的首字母,字段由汉字.英文.数字以及“-”构成,百度了一堆,找到如下方法,记录一下,以备后用! 首先建立一个函数 --生成拼音首码 )) ) --WITH ENCRYPTION as begin declare @intLen int ) ) set @intLen = len(@str) set @strRet = '' begin set @temp = '' select @temp = case ) >= '帀' th…
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) --如果非汉字字符,返回原字符 set @PY=@PY+(case when unicode(@word) between 19968…
if exists (select * from sysobjects where id = object_id(N'[fn_ChineseToSpell]') and xtype in (N'FN', N'IF', N'TF')) www.2cto.com drop function [fn_ChineseToSpell]GO/*创建取拼音首字母函数*/ create function [dbo].[fn_ChineseToSpell](@strChinese varchar(500)='')…
-- ============================================= -- 功能:汉字转换成拼音首字母 首字母查 -- ============================================= )='') ) as begin --定义变量 ), @ii int ),) --设置初始值 --开始循环取出没个字符 while @ii<@strlen begin ,,) if @chn>'z' ,@c = case chn when @chn then…
ql获取汉字的拼音首字母 if exists (select * from sysobjects where id = object_id(N'[fn_ChineseToSpell]') and xtype in (N'FN', N'IF', N'TF')) www.2cto.com drop function [fn_ChineseToSpell] GO /*创建取拼音首字母函数*/ create function [dbo].[fn_ChineseToSpell](@…