sql表有两个字段,前一字段是中文汉字,怎么才可以实现后一字段是前一字段的拼音索引

来源:百度知道 编辑:UC知道 时间:2024/05/30 23:17:51
name pinyin

成功绝对有机会 CGJDYJH
无情恋梦 WQLM
是你违背我[闽南]
梦醒心也碎[闽南]
就像这样的给后面做拼音索引

这样:UPDATE 表名 set 拼音字段=dbo.getpy(汉字字段)

GETPY是自定义函数,下面是函数脚本:

create FUNCTION GetPy
(@Str varchar(2000)='')
RETURNS VARCHAR(5000)
as
BEGIN
DECLARE @RETURN VARCHAR(5000)
declare @strlen int,@ii int
declare @n int,@c char(1),@chn nchar(1)

select @strlen=len(@str),@return='',@ii=0
set @ii=0
while @ii<@strlen
begin
select @ii=@ii+1,@n=63,@chn=substring(@str,@ii,1)
if @chn>'z'
select @n = @n +1
,@c = case chn when @chn then char(@n) else @c end
from(
select top 27 * from (
selec