比如:create table #t(a varchar(100))insert into #t(a)
select 'zbcd*'
union all
select 'dddd'
union all
select 'sssdw'
union all
select '2ssdw*'
我想把把#t.a的最后带“*”放在最下面,如数据:
  a
dddd
sssdw
2ssdw*
zbcd*如何写sql语句

解决方案 »

  1.   


    select * from #t order by charindex('*',a),a
      

  2.   

    select * from #t
    order by case when a like '%*%' then 1 else 0 end,a
      

  3.   

    create table #t(a varchar(100))insert into #t(a)
    select 'zbcd*'
    union all
    select 'dddd'
    union all
    select 'sssdw'
    union all
    select '2ssdw*'
    go
    select * from #t order by right(a,1) desc
    /*
    a
    ----------------------------------------------------------------------------------------------------
    sssdw
    dddd
    zbcd*
    2ssdw*(4 行受影响)*/
      

  4.   

    select * from #t 
    order by case when right(a,1)='*' then 1 else 0 end,a