输入'L'或'l',可查询数据库中人员姓名以L或l开头的名单;如李四,李湘,赖可。
其他字母类似
大虾帮忙哈

解决方案 »

  1.   

    写一个函数过去拼音首字母就可以like了
      

  2.   

    create function [dbo].[funcGetPY](@str nvarchar(4000))
    returns nvarchar(4000)
    as
    begin
    declare @strlen int,@re nvarchar(4000)
    declare @t table(chr nchar(1) collate Chinese_PRC_CI_AS,letter nchar(1))
    insert into @t(chr,letter)
      select '吖','A' union all select '八','B' union all
      select '嚓','C' union all select '咑','D' union all
      select '妸','E' union all select '发','F' union all
      select '旮','G' union all select '铪','H' union all
      select '丌','J' union all select '咔','K' union all
      select '垃','L' union all select '嘸','M' union all
      select '拏','N' union all select '噢','O' union all
      select '妑','P' union all select '七','Q' union all
      select '呥','R' union all select '仨','S' union all
      select '他','T' union all select '屲','W' union all
      select '夕','X' union all select '丫','Y' union all
      select '帀','Z'
      select @strlen=len(@str),@re=''
      while @strlen>0
      begin
        select top 1 @re=letter+@re,@strlen=@strlen-1
          from @t a where chr<=substring(@str,@strlen,1)
          order by chr desc
        if @@rowcount=0
          select @re=substring(@str,@strlen,1)+@re,@strlen=@strlen-1
      end
      return(@re)
    end
      

  3.   

    -->创建函数:
    create   function   f_GetPy(@str   nvarchar(4000)) 
    returns   nvarchar(4000) 
    as 
    begin 
    declare   @strlen   int,@re   nvarchar(4000) 
    declare   @t   table(chr   nchar(1)   collate   Chinese_PRC_CI_AS,letter   nchar(1)) 
    insert   into   @t(chr,letter) 
        select   '吖 ', 'A '   union   all   select   '八 ', 'B '   union   all 
        select   '嚓 ', 'C '   union   all   select   '咑 ', 'D '   union   all 
        select   '妸 ', 'E '   union   all   select   '发 ', 'F '   union   all 
        select   '旮 ', 'G '   union   all   select   '铪 ', 'H '   union   all 
        select   '丌 ', 'J '   union   all   select   '咔 ', 'K '   union   all 
        select   '垃 ', 'L '   union   all   select   '嘸 ', 'M '   union   all 
        select   '拏 ', 'N '   union   all   select   '噢 ', 'O '   union   all 
        select   '妑 ', 'P '   union   all   select   '七 ', 'Q '   union   all 
        select   '呥 ', 'R '   union   all   select   '仨 ', 'S '   union   all 
        select   '他 ', 'T '   union   all   select   '屲 ', 'W '   union   all 
        select   '夕 ', 'X '   union   all   select   '丫 ', 'Y '   union   all 
        select   '帀 ', 'Z ' 
        select   @strlen=len(@str),@re= ' ' 
        while   @strlen> 0 
        begin 
            select   top   1   @re=letter+@re,@strlen=@strlen-1 
                from   @t   a   where   chr <=substring(@str,@strlen,1) 
                order   by   chr   desc 
            if   @@rowcount=0 
                select   @re=substring(@str,@strlen,1)+@re,@strlen=@strlen-1 
        end 
        return(@re) 
    end 
    go 
    -->调用 
    select * from tb where dbo.f_GetPy(Name)='L'
      

  4.   

    这个一定要拼音库的.Top
    2 楼zjcxc(邹建)回复于 2006-06-01 19:54:20 得分 95/*--从全拼音中得到汉字拼音  
       
      首先,用输入法生成器(Imegen.exe)的逆转换功能  
      将全拼的码表文件   WINPY.MB   转换成文本文件   c:\winpy.txt  
      然后用下面的语句导入到数据库中  
        下面只是显示了读取并显示的过程,并没有存储到具体的表中  
       
      读取语句中的:  
      with(datafiletype='widechar')     的作用是处理unicode数据  
      我是用win2000测试的,转换的文本文件编码是unicode  
      如果是编码是ansi,则不要这句  
       
      查看文本文件编码,可以用记事本打开文本文件,另存为,就可以看到当前编码  
      --*/  
       
      --创建临时表  
      create   table   #t(a   varchar(500))  
       
      --导入数据  
      bulk   insert   #t   from   'c:\winpy.txt'  
      with(datafiletype='widechar')  
       
      --删除表头  
      set   rowcount   12  
      delete   from   #t  
      set   rowcount   0  
       
      --分拆处理  
      select   汉字=left(a,patindex('%[a-z]%',a)-1)  
      ,拼音=stuff(a,1,patindex('%[a-z]%',a)-1,'')  
      from   #t  
      --where   patindex('%[a-z]%',a)=2     --如果是获得单字的读音  
       
      --删除测试  
      drop   table   #tTop
    3 楼zjcxc(邹建)回复于 2006-06-01 19:56:16 得分 0
    --   使用拼音库处理拼音的示例  
       
       
      /*--获得汉字拼音的函数  
       
            需要创建一个拼音表,包含所有汉字的发音,这个可以通过转换全拼输入法的编码库得到,这里仅举了一个简单的例子.  
      --邹建   2003.10--*/  
       
      --创建汉字拼音库  
      create   table   YingShe(CHR     char(2),PY   varchar(10))  
      insert   YingShe    
      select   '长','chang'  
      union   all   select   '长','zhang'  
      union   all   select   '城','cheng'  
      union   all   select   '科','kel'  
      union   all   select   '技','ji'  
      union   all   select   '金','jin'  
      union   all   select   '立','li'  
      union   all   select   '章','zhang'  
      union   all   select   '公','gong'  
      union   all   select   '司','si'  
       
      /*--下面是两个函数,一个以表的形式返回某个字符串的全部拼音,一个返回某某个字符串的其中一个拼音  
      --*/  
       
      go  
      --获取汉字拼音的函数--返回所有的拼音  
      create   function   f_getpy_tb(@str   varchar(100))  
      returns   @tb   table(re   varchar(8000))  
      as  
      begin  
      declare   @re   table(id   int,re   varchar(8000))     --数据处理中间表  
       
      declare   @i   int,@ilen   int,@splitchr   varchar(1)  
      select   @splitchr='   ' --两个拼音之间的分隔符(目的是为了通用性考虑)  
      ,@i=1,@ilen=len(@str)  
       
      insert   into   @re   select   @i,py   from   YingShe   where   chr=substring(@str,@i,1)  
      while   @i<@ilen  
      begin  
      set   @i=@i+1  
      insert   into   @re   select   @i,re+@splitchr+py   from   @re   a,YingShe   b  
      where   a.id=@i-1   and   b.chr=substring(@str,@i,1)  
      end  
       
      insert   into   @tb   select   re   from   @re   where   id=@i  
      return    
      end  
      go  
       
      --获取汉字拼音的函数--返回汉字的某一个拼音  
      create   function   f_getpy(@str   varchar(100))  
      returns   varchar(8000)  
      as  
      begin  
      declare   @re   varchar(8000)  
       
      declare   @i   int,@ilen   int,@splitchr   varchar(1)  
      select   @splitchr='   ' --两个拼音之间的分隔符(目的是为了通用性考虑)  
      ,@i=1,@ilen=len(@str)  
       
      select   @re=py   from   YingShe   where   chr=substring(@str,@i,1)  
      while   @i<@ilen  
      begin  
      set   @i=@i+1  
      select   top   1   @re=@re+@splitchr+py  
      from   YingShe   where   chr=substring(@str,@i,1)  
      end  
       
      return(@re)  
      end  
      go  
       
      --测试  
      --返回'长城'的所有可能拼音  
      select   *   from   dbo.f_getpy_tb('长城')  
       
        --应用案例:  
       
      create   table   MyTable(Name   varchar(10),ID   int)  
        insert   MyTable   select   '长城科技',1  
      union   all   select   '金长城科技',2  
        union   all   select   '立章城公司',3  
       
      go  
       
      --查询包含与'长城'拼音一样的记录:  
      select   *   from   mytable  
      where   exists(select   1   from   dbo.f_getpy_tb('长城')   where   dbo.f_getpy(name)   like   '%'+re+'%')  
       
      --删除表  
      drop   table   YingShe,mytable  
      --删除拼音函数  
      drop   function   f_getpy,f_getpy_tb   
      

  5.   

    我记得网上有一篇Delphi处理这样问题的函数。
      

  6.   

    3楼的调用改下:-->调用 
    select * from tb where dbo.f_GetPy(Name) like 'L%'