select houseid,projname,city,room,hall,toilet,kitchen,buildingarea,livingarea,price,privider from (select * ,Row_Number() OVER (ORDER BY registdate desc) as rownum from ( select top 16600 houseid ,registdate from COMMERCE_lease_BJ_mls as a (nolock) where 1=1 and city='北京' and purpose='写字楼' order by registdate desc ) a ) as b where rownum >16575 ORDER BY registdate desc
create PROCEDURE page
@pageSize int=2,
@pageIndex int=1,
@tbName varchar(50)
AS
BEGIN
declare @strSql nvarchar(4000);
declare @strCount nvarchar(4000);
declare @num int;
set @strCount='select @num=count(*) from '+@tbName;
execute sp_executesql @strCount,N'@num int output',@num output;
set @strSql='select * from (select row_number() over(order by id desc) rowid,* from (select top '+str(@pageSize*@pageIndex)+' * from '+@tbName+' order by id desc) a )p where p.rowid>'+str((@pageIndex-1)*@pageSize)+' order by id desc';
exec (@strSQL)
END
GO