sqlserver取字符串拼音首字母
sqlserver 使用函数获取一个字符串的拼音首字母
createfunction dbo.fn_getpinyin(
@strnvarchar(max))
returnsnvarchar(max)asbegin
declare@wordnchar(1),@PYnvarchar(max)
set@PY=""
whilelen(@str)>0
begin
set@word=left(@str,1)
--如果非汉字字符,返回原字符
set@PY=@PY+(casewhenunicode(@word) between19968and19968+20901
then (selecttop1 PY
from
(
select"A"as PY,N"驁"as word
unionallselect"B",N"簿"
unionallselect"C",N"錯"
unionallselect"D",N"鵽"
unionallselect"E",N"樲"
unionallselect"F",N"鰒"
unionallselect"G",N"腂"
unionallselect"H",N"夻"
unionallselect"J",N"攈"
unionallselect"K",N"穒"
unionallselect"L",N"鱳"
unionallselect"M",N"旀"
unionallselect"N",N"桛"
unionallselect"O",N"漚"
unionallselect"P",N"曝"
unionallselect"Q",N"囕"
unionallselect"R",N"鶸"
unionallselect"S",N"蜶"
unionallselect"T",N"籜"
unionallselect"W",N"鶩"
unionallselect"X",N"鑂"
unionallselect"Y",N"韻"
unionallselect"Z",N"咗"
) T
where word>=@word collate Chinese_PRC_CS_AS_KS_WS
orderby PY asc)
else@wordend)
set@str=right(@str,len(@str)-1)
end
return@PY
end
以上是 sqlserver取字符串拼音首字母 的全部内容, 来源链接: utcz.com/z/531451.html