日期:2014-05-17 浏览次数:20406 次
select * from ( select row_number() over(order by col1) rn,* from 你的表) t where rn between 1 and 100--你的条件
------解决方案--------------------
select * from ( select row_number() over(order by 排序的列) row_id,* from tb where.......... ) as t where row_id between 1 and 100
------解决方案--------------------
select * from ( select row_number() over(order by 排序的列) rn,* from tb where xxx=yyy ) as a where rn between 1 and 100
------解决方案--------------------
/// <summary> /// 获得查询分页数据 /// </summary> public DataSet GetPageList(int pageSize, int currentPage, string strWhere, string filedOrder) { StringBuilder strSql = new StringBuilder(); if (currentPage > 0) { int topNum = pageSize * currentPage; strSql.Append("select top " + pageSize + " Id,Title,Author,Form,Keyword,Zhaiyao,ClassId,ImgUrl,Daodu,Content,Click,IsMsg,IsTop,IsRed,IsHot,IsSlide,IsLock,AddTime from Article"); strSql.Append(" where Id not in(select top " + topNum + " Id from Article"); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } strSql.Append(" order by " + filedOrder + ")"); if (strWhere.Trim() != "") { strSql.Append(" and " + strWhere); } strSql.Append(" order by " + filedOrder); } else { strSql.Append("select top " + pageSize + " Id,Title,Author,Form,Keyword,Zhaiyao,ClassId,ImgUrl,Daodu,Content,Click,IsMsg,IsTop,IsRed,IsHot,IsSlide,IsLock,AddTime from Article"); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } strSql.Append(" order by " + filedOrder); } return DbHelperOleDb.Query(strSql.ToString()); }
------解决方案--------------------
select * from ( select row_number() over(order by col1) rn,* from 你的表) t where rn between 1 and 100--你的条件
------解决方案--------------------
2.分页SQL语句 select * from(select (row_number() OVER (ORDER BY tab.ID Desc)) as rownum,tab.* from 表名 As tab) As t where rownum between 起始位置 And 结束位置 set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER PROC [dbo].[PROCE_PageView2000] ( @tbname nvarchar(100), --要分页显示的表名 @FieldKey nvarchar(1000), --用于定位记录的主键(惟一键)字段,可以是逗号分隔的多个字段 @PageCurrent int=1, --要显示的页码 @PageSize int=10, --每页的大小(记录数) @FieldShow nvarchar(1000)='', --以逗号分隔的要显示的字段列表,如果不指定,则显示所有字段 @FieldOrder nvarchar(1000)='', --以逗号分隔的排序字段列表,可以指定在字段后面指定DESC/ASC @WhereString nvarchar(1000)=N'', --查询条件 @RecordCount int OUTPUT --总记录数 ) AS SET NOCOUNT ON --检查对象是否有效 --IF OBJECT_ID(@tbname) IS NULL --BE