比如select ROW_NUMBER() over (order by id) as RowId,* from adonet查出的结果是以ID排序,在前面多加一列RowId。
代码如下 | 复制代码 |
RowId id name addr datet 1 000000 onepc0 cnblogs - 0 2011-10-25 18:25:04.093 select ROW_NUMBER() over (order by id desc) as RowId,* from adonet ---ID为desc序排列 RowId id name addr datet 1 046606 00000 cnblogs - 46606 2014-06-22 17:25:04.093 |
select ROW_NUMBER() over (order by id desc) as RowId,* from adonet order by id或者rowid 这里排的话,查下表就清楚了。
MSSQL存储过程
代码如下 | 复制代码 |
--select id,name,addr,datet from adonet --select id,name,addr,datet,ROW_NUMBER() over (order by datet) aaa from adonet order by aaa desc --select GETDATE() --select * from (select ROW_NUMBER() over (order by id) as RowId,* from adonet) temptable --where RowId>=1 and RowId<=100 use wentest if exists(select * from sys.sysobjects where type='p' and name='row_fy') drop procedure row_fy go create procedure row_fy @pagesize int, --分页大小 @page int --当前第几页 --@outfynum int output with encryption --加密 as --declare @temp int select * from ( select ROW_NUMBER() over (order by id) as RowId,* from adonet ) as temptable where RowId>=(@page-1)*@pagesize+1 and RowId<=@page*@pagesize |
执行
row_fy 100,1