select top 2 M.ver from (select distinct ver  from  a )M order by M.ver  desc

解决方案 »

  1.   

    create table t
    (id int identity(1,1),ver char(20))insert t
    select '1,2,4,5,9,6' union all
    select '8,5,6,7' union all
    select '10,20,3,56'
    gocreate function f_go(@col varchar(100))
    returns varchar(10)
    as
    begin
      declare @i int,@m varchar(10)
      select @i=len(@col+'a')-2
      declare @t table(col varchar(10))
      while charindex(',',@col)>0
      begin
       insert @t values (left(@col,charindex(',',@col)-1))
       set @col=stuff(@col,1,charindex(',',@col),'')
      end
     insert @t values (@col)
     
      
      select @m=max(col) from @t
     return(@m)
    end
    goselect id,dbo.f_go(ver) as max_ver from t
    drop function f_godrop table tid          max_ver    
    ----------- ---------- 
    1           9
    2           8
    3           56        (所影响的行数为 3 行)
      

  2.   

    请问 samfeng_2003(凤翼天翔)
    create function f_go(@col varchar(100))
    returns varchar(10)
    as
    begin
      declare @i int,@m varchar(10)
      select @i=len(@col+'a')-2
      declare @t table(col varchar(10))
      while charindex(',',@col)>0
      begin
       insert @t values (left(@col,charindex(',',@col)-1))
       set @col=stuff(@col,1,charindex(',',@col),'')
      end
     insert @t values (@col)
     
      
      select @m=max(col) from @t
     return(@m)
    end
    go
    可以写入存储过程吗?人好笨,写过别的,这个不会,教教我好吗?谢谢!
      

  3.   

    select top 2 ver as ver from a
    order by ver desc