杨的空间
业精于勤,荒于嬉,行成于思,毁于随

导航

<2025年4月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910
统计
  • 随笔 - 67
  • 文章 - 13
  • 评论 - 60
  • 引用 - 0

常用链接

留言簿(6)

随笔分类

随笔档案

文章分类

相册

WEB开发相关

其它链接

  • 你所不知道的牛奶的缺点
  • 喝牛奶要特别注意的一些知识
  • 旁观者的Blog (rss)
  • 参与移动增值业务平台开发这些年来,不断地遇到新领域新知识点,屡屡感受到新进入者的迷惑和彷徨,所以对遇到的每一个问题都详细记录问题现象、解决思路以及解决方案,并在blog中留下印迹,以备他日有心人google之而知之。你们的新手之痛,你们的新业务发展之初的思路混沌,我都感同身受,所以欢迎和我一起探讨这些话题,诸如IVR/SMS/MMS/WAP/Podcast/SIP/JavaME/Web2.0等等,知无不言言无不尽。

搜索

  •  

最新评论

阅读排行榜

评论排行榜

 

 

--取得字符串每个汉字的拼音首字母

create function f_GetPy(@str nvarchar(4000))

returns nvarchar(4000)

as

begin

declare @strlen int,@re nvarchar(4000)

declare @t table(chr nchar(1) collate Chinese_PRC_CI_AS,letter nchar(1))

insert into @t(chr,letter)

select '','A' union all select '','B' union all

select '','C' union all select '','D' union all

select '','E' union all select '','F' union all

select '','G' union all select '','H' union all

select '','J' union all select '','K' union all

select '','L' union all select '','M' union all

select '','N' union all select '','O' union all

select '','P' union all select '','Q' union all

select '','R' union all select '','S' union all

select '','T' union all select '','W' union all

select '','X' union all select '','Y' union all

select '','Z'

select @strlen=len(@str),@re=''

while @strlen>0

begin

select top 1 @re=letter+@re,@strlen=@strlen-1

from @t a where chr<=substring(@str,@strlen,1)

order by chr desc

if @@rowcount=0

select @re=substring(@str,@strlen,1)+@re,@strlen=@strlen-1

end

return(@re)

end

go


--调用

select dbo.f_GetPy('中国')
--结果:ZG


--取得字符串第一个汉字的拼音首字母
create function f_GetFirstPy(@str nvarchar(1))

returns nvarchar(1)

as

begin

declare @strlen int,@re nvarchar(1)

declare @t table(chr nchar(1) collate Chinese_PRC_CI_AS,letter nchar(1))

insert into @t(chr,letter)

select '','A' union all select '','B' union all

select '','C' union all select '','D' union all

select '','E' union all select '','F' union all

select '','G' union all select '','H' union all

select '','J' union all select '','K' union all

select '','L' union all select '','M' union all

select '','N' union all select '','O' union all

select '','P' union all select '','Q' union all

select '','R' union all select '','S' union all

select '','T' union all select '','W' union all

select '','X' union all select '','Y' union all

select '','Z'

select @strlen=len(@str),@re=''

while @strlen>0

begin

select top 1 @re=letter+@re,@strlen=@strlen-1

from @t a where chr<=substring(@str,@strlen,1)

order by chr desc

if @@rowcount=0

select @re=substring(@str,@strlen,1)+@re,@strlen=@strlen-1

end

return(@re)

end

go

--调用

select dbo.f_GetFirstPy('中国')
--结果:Z
posted on 2007-11-24 13:58 阅读(422) 评论(0)  编辑 收藏 引用
只有注册用户登录后才能发表评论。