在数据库表中选出名字列表。。就是说,在一个表中有很多名字(都是中文),怎么才能查询时,按字母顺序排列出名字呢。。就向百度的mp3一样,当点击大陆男歌手时候,就按字母顺序列出所有歌手的名字

解决方案 »

  1.   

    SELECT * FROM 表 ORDER BY 名字列 COLLATE Chinese_PRC_CS_AS_KS_WS
      

  2.   

    好像默认就是按字母顺序排的declare @t table(a varchar(100))
    insert into @t select '阿'
    insert into @t select '副'
    insert into @t select '波'select * from @t order by a
      

  3.   

    CREATE function F_GetPybm(@Str nvarchar(400))
    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 @t 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)
    endselect F_GetPybm(名) from 表 order by F_GetPybm(名) asc
      

  4.   

    select 名 from 表 order by F_GetPybm(名) asc,名