SQL分页查询语句


----方法一----------------------------------------------------------------
select * from (select *, ROW_NUMBER() OVER (ORDER BY DeptName) as rownum from #tt) as tmpTable where rownum > ((@currpageno - 1) * @intPageSize) and rownum <= (((@currpageno - 1) * @intPageSize) + @intPageSize)

----方法二----------------------------------------------------------------
select top (@intPageSize) * from #tt where DeptName not in( select top ((@currpageno-1)*@intPageSize) DeptName  from #tt)

----方法三----------------------------------------------------------------

declare @no_show_recordcount int
select @no_show_recordcount = @show_recordcount - (@currpageno - 1) * @intPageSize

set @sql = 'select top  '+convert(varchar, @intPageSize) +'  * from ( select top '+convert(varchar,@no_show_recordcount)+' *  from #tt order by UserName desc ) a order by a.UserName asc'

原文地址:https://www.cnblogs.com/xytmj/p/xytmj_SQL_PageNum.html