sqlserver取字符串拼音首字母

database

sqlserver 使用函数获取一个字符串的拼音首字母

createfunction dbo.fn_getpinyin

(

@strnvarchar(max)

)

returnsnvarchar(max)

as

begin

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

回到顶部