取汉字拼音首字母的存储过程
类别: 数据库教程
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 and 19968+20901
then (
select top 1 PY
from
(
select \'A\' as PY,N\'??\' as word
union all select \'B\',N\'簿\'
union all select \'C\',N\'邋\'
union all select \'D\',N\'?z\'
union all select \'E\',N\'?捃'
union all select \'F\',N\'鲻\'
union all select \'G\',N\'穆\'
union all select \'H\',N\'??\'
union all select \'J\',N\'?h\'
union all select \'K\',N\'烽\'
union all select \'L\',N\'鼢\'
union all select \'M\',N\'?孳'
union all select \'N\',N\'??\'
union all select \'O\',N\'?a\'
union all select \'P\',N\'曝\'
union all select \'Q\',N\'?蒈'
union all select \'R\',N\'?U\'
union all select \'S\',N\'我\'
union all select \'T\',N\'回\'
union all select \'W\',N\'?F\'
union all select \'X\',N\'枰\'
union all select \'Y\',N\'??\'
union all select \'Z\',N\'??\'
) T
where word>=@word collate Chinese_PRC_CS_AS_KS_WS
order by PY ASC
)
else @word
end)
set @str=right(@str,len(@str)-1)
end
return @PY
end
(
@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 and 19968+20901
then (
select top 1 PY
from
(
select \'A\' as PY,N\'??\' as word
union all select \'B\',N\'簿\'
union all select \'C\',N\'邋\'
union all select \'D\',N\'?z\'
union all select \'E\',N\'?捃'
union all select \'F\',N\'鲻\'
union all select \'G\',N\'穆\'
union all select \'H\',N\'??\'
union all select \'J\',N\'?h\'
union all select \'K\',N\'烽\'
union all select \'L\',N\'鼢\'
union all select \'M\',N\'?孳'
union all select \'N\',N\'??\'
union all select \'O\',N\'?a\'
union all select \'P\',N\'曝\'
union all select \'Q\',N\'?蒈'
union all select \'R\',N\'?U\'
union all select \'S\',N\'我\'
union all select \'T\',N\'回\'
union all select \'W\',N\'?F\'
union all select \'X\',N\'枰\'
union all select \'Y\',N\'??\'
union all select \'Z\',N\'??\'
) T
where word>=@word collate Chinese_PRC_CS_AS_KS_WS
order by PY ASC
)
else @word
end)
set @str=right(@str,len(@str)-1)
end
return @PY
end
- 上一篇: 复制表结构的通用存储过程
- 下一篇: SQL SERVER中格式化表中的数据
-= 资 源 教 程 =-
文 章 搜 索