TOP只能是一个自然数嘛,所以用表达式是会出错的。select top 5 * from ....这样就没有问题
问一下, SET ROWCOUNT @QuestionNum 是针对全局开始只针对这一次查询?
exec('SELECT Top '+cast(@每页大小 as varchar)+' * FROM T WHERE SortField NOT IN (SELECT TOP '+cast(@每页大小*@第几页 as varchar)+' SortField from T )')
exec 'select top' +cast(@QuestionNum as char)+'* from quession where ……'
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
SET ROWCOUNT @QuestionNum
是针对全局开始只针对这一次查询?
@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
不是针对全局的,只对当前进程有效。