·您的位置: 首页 » 资源教程 » 编程开发 » 数据库 » 取得拼音字头的存储过程

取得拼音字头的存储过程

类别: 数据库教程  评论数:0 总得分:0
IF EXISTS (SELECT *
FROM sysobjects
WHERE name = N\'NWGetPYFirst\')
DROP FUNCTION NWGetPYFirst
GO

CREATE FUNCTION NWGetPYFirst
(@str varchar(500) = \'\')
RETURNS varchar(500)
AS
BEGIN
Declare @strlen int,
@return varchar(500),
@ii int,
@c char(1),
@chn nchar(1)
--//初始化变量
Declare @pytable table(
chn char(2) COLLATE Chinese_PRC_CS_AS NOT NULL,
py char(1) COLLATE Chinese_PRC_CS_AS NULL,
PRIMARY KEY (chn)
)
insert into @pytable values(\'吖\', \'A\')
insert into @pytable values(\'八\', \'B\')
insert into @pytable values(\'嚓\', \'C\')
insert into @pytable values(\'?鲕', \'D\')
insert into @pytable values(\'??\', \'E\')
insert into @pytable values(\'发\', \'F\')
insert into @pytable values(\'旮\', \'G\')
insert into @pytable values(\'铪\', \'H\')
insert into @pytable values(\'丌\', \'I\')
--insert into @pytable values(\'丌\', \'J\')
insert into @pytable values(\'咔\', \'K\')
insert into @pytable values(\'垃\', \'L\')
insert into @pytable values(\'?`\', \'M\')
insert into @pytable values(\'??\', \'N\')
insert into @pytable values(\'噢\', \'O\')
insert into @pytable values(\'?r\', \'P\')
insert into @pytable values(\'七\', \'Q\')
insert into @pytable values(\'?哕', \'R\')
insert into @pytable values(\'仨\', \'S\')
insert into @pytable values(\'他\', \'T\')
insert into @pytable values(\'?苘', \'U\')
--insert into @pytable values(\'?苘', \'V\')
--insert into @pytable values(\'?苘', \'W\')
insert into @pytable values(\'夕\', \'X\')
insert into @pytable values(\'丫\', \'Y\')
insert into @pytable values(\'??\', \'Z\')

select @strlen = len(@str), @return = \'\', @ii = 0
--//循环整个字符串,用拼音的首字母替换汉字
while @ii < @strlen
begin
select @ii = @ii + 1, @chn = substring(@str, @ii, 1)
if @chn > \'z\' --//检索输入的字符串中有中文字符
SELECT @c = max(py)
FROM @pytable
where chn <= @chn
else
set @c=@chn

set @return=@return+@c
end
return @return
END
GO

-- =============================================
-- Example to execute function
-- =============================================
SELECT dbo.NWGetPYFirst(\'梦想国度\'), dbo.NWGetPYFirst(\'noctwolf分享源码\'), dbo.NWGetPYFirst(\'\')
GO
-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1