declare @QuestionNum  int
select @QuestionNum =100
SET ROWCOUNT @QuestionNum 
select * from Question where ……

解决方案 »

  1.   

    TOP只能是一个自然数嘛,所以用表达式是会出错的。select top 5 * from ....这样就没有问题
      

  2.   

    问一下,
    SET ROWCOUNT @QuestionNum 
    是针对全局开始只针对这一次查询?
      

  3.   

    exec('SELECT Top '+cast(@每页大小 as varchar)+' * FROM T WHERE SortField NOT IN (SELECT TOP '+cast(@每页大小*@第几页 as varchar)+' SortField from T )')
      

  4.   

    exec 'select top' +cast(@QuestionNum as char)+'* from quession where ……'
      

  5.   

    Create Procedure EO_SelectRandQuestion
    @myCouId int,
    @myUntId tinyInt,
    @myqtID int,
    @Lcft tinyint,
    @Ucft tinyint,
    @myQNum int
    asdeclare @strSql Nvarchar(1024)
    select @strSql=N'select top'+space(1)+ltrim(rtrim(str(@myQnum)))+space(1)+'* from Question where CouId= @MycouId and UntId=@myUntId and Qtid=@myQtId and cft>=@Lcft and cft<=@Ucft order by NewId()'exec sp_executesql @strSql,N'@myCouId int,@myUntId tinyInt,@myqtID int,@Lcft tinyint,@Ucft tinyint',@myCouId,@myUntId,@myqtID,@Lcft,@Ucft
      

  6.   

    SET ROWCOUNT @QuestionNum 
    不是针对全局的,只对当前进程有效。