top后不能用变量
只能拼字符串

解决方案 »

  1.   

    create proc max_speed
    @table nvarchar(20),
    @currentpage int,
    @pagesize int,
    @orderby nvarchar(20)
    as
    begin
      declare @s varchar(1000)
      set @s = 'SELECT TOP '+rtrim(@pagesize)+' * FROM '+@table+'
                WHERE ('+@orderby+' NOT IN 
                               (SELECT TOP '+rtrim(@pagesize*@currentpage)+' id 
                                FROM '+@table+'
                                ORDER BY '+@orderby+'))
                ORDER BY '+@orderby+''
      exec(@s)
    end