日期:2014-05-17 浏览次数:20524 次
create procedure proc_GetListByPageIndex ( @pageIndex int=1, @pageSize int=5 ) as select top (@pageSize) * from employees where employeeid not in ( select top ((@pageSize)*(@pageIndex-1)) employeeid from employees order by employeeid )order by employeeid
create procedure proc_GetListByPageIndex ( @pageIndex int=1, @pageSize int=5 ) as EXEC ('select top '+@pageSize+' * from employees where employeeid not in ( select top '+@pageSize+'*('+@pageIndex+'-1)+employeeid from employees order by employeeid)order by employeeid' )
------解决方案--------------------
declare @num int
set @num =10
DECLARE @sqlstr NVARCHAR(200)
SELECT @sqlstr = 'select top ('+CAST(@num AS VARCHAR(10)) + ') id from test '
EXEC(@sqlstr)