select * from T order by case when col is null then 0 else 1 end asc

解决方案 »

  1.   

    select * from t order by case when col1 is null then 0 else 1 end +case when col2 is null then 0 else 1 end asc
    --如果是按列数null取值时--楼主的好像是空字符:
    select   *   from   T   order   by   case   when   col  =''   then   0   else   1   end   asc
      

  2.   

    调用系统表syscolumns..
    楼主可列出一个数据。。
    生成的格式相同
      

  3.   

    用以下语句获取列:
    select name from syscolumns where id = object_id('T')
      

  4.   

    给楼主写一个通用的存储过程:create procedure shiyan(@tname varchar(10))
    as
    begin
        declare @sql varchar(8000)
        set @sql=''    
        select 
            @sql=@sql+'+(case when '+name+' is null then 0 else 1 end)' 
        from 
            syscolumns 
        where  
            id=object_id(@name) 
            set @sql='select * from  '+@tname+' order by  '+stuff(@sql,1,1,'')+' asc'    
        exec(@sql)
    endgoexec shiyan('表名')