日期:2014-05-19  浏览次数:20595 次

想将中文转化问拼音,出现问题了,帮忙看看
需要将字段name由中文转化问拼音,大家帮忙看看,有问题了,
declare   @hanzi   nvarchar(500),
                @pinyin     nvarchar(20),
                @name   nvarchar(500),
                @nameen   nvarchar(1000),
                @i   int,
                @conseq     int
              set   @i=1
declare   topinyin   cursor   for   select   name,conseq   ,nameen   from   conmas   where   conseq <1000   order   by   conseq/*name为中文字段,conseq为主键,int,nameen为name转化为拼音的字段,默认值为 ' '*/
                      open   topinyin
                              fetch   next   from   topinyin   into   @name,@conseq,@nameen
                            print   @conseq
                      while   @@FETCH_STATUS   =   0
                            Begin
                                    while     @i <=len(@name)
                                    begin  
                                        select   @hanzi=   substring(@name,@i,1)  
                                select   @pinyin=   拼音   from   汉字拼音表     where     patindex(   '% '+@hanzi+ '% ',汉字) <> 0
                                              update   conmas   set   nameen=nameen+ '   '+@pinyin   where       conseq=@conseq
                                      select   @i=@i+1  
                                      end  
                              fetch   next   from   topinyin   into   @name,@conseq,@nameen
                        return
                    End
    CLOSE   topinyin
deallocate   topinyin/*
汉字拼音表格式为
拼音     汉字
a           <所有发音问a的汉字>
ai         <所有发音问ai的汉字> */




------解决方案--------------------