建立乙個查詢,執行下面的語句生成函式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 @te = ''
select @temp = case
when substring(@str,@intlen,1) >= '帀' then 'z'
when sub程式設計客棧string(@str,@intlen,1) >= '丫' then 'y'
when substring(@str,@intlen,1) >= '夕' then 'x'
when substring(@str,@intlen,1) >= '屲' then 'w'
when substring(@str,@intlen,1) >= '他' th程式設計客棧en '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.fwww.cppcns.comn_getpy(product_name) as pymc
from dbo.t_product
本文標題: sql server自動生成拼音首字母的函式
本文位址:
sql server自動生成拼音首字母的函式
建立乙個查詢,執行下面的語句生成函式fn getpy 生成拼音首碼 create function fn getpy str nvarchar 4000 returns nvarchar 4000 with encryption as begin declare intlen int declare...
SQL SERVER2008 自動生成索引
declare ix table index handle int,eq nvarchar 4000 included columns nvarchar 4000 name varchar 100 dbname varchar 30 with idx as select a.index handle...
PHP生成中文拼音
以下為引用的內容 php class chinesespell return spell 取漢字第乙個拼音 param string chinese 要轉換的漢字 param int length 返回的長度 return string public function getfirstspell c...