asp.net分页的SQL语句及存储过程

简介: SQL语句:利用 not in   select top pageSize * from table where tid not in (select top (pageInd...

SQL语句:

利用 not in    

  select top pageSize * from table where tid not in (select top (pageIndex-1)*pagesize tid from 表名) ;

  --------------或者    

  select * from ( select *,Row_Number() over(order by id) RowNumber from 表名) t where t.RowNumber>=2 and t.RowNumber<=10;  
  


存储过程:

create  Procedure GetPageData(      

  @PageIndex  int =1,      

  @PageSize   int =10,      

  @RowCount  int output,      

  @PageCount  int  output)

  as

  Declare  @sql nvarchar(225),@sqlcount nuachar(225)

  select @rowcount=count(sid),@pagecount=ceiling( count(sid)+0.0 )/@pagesize  from studentsset  

  @sql='select top '+str(@pagesize)+' * from students,classes where scid=cid and sid not in(select top) '  +str( (@pageIndex)-1 )*pagesize)  +'sid from students'

  print  @sql

  exec(@sql)

 --执行  
Declare  
@rowcount int, 
@pagecount int 
exec  GetPageData  1,3,@rowcount out ,@pagecount outputselect  rowcount,@pagecount

 
 


相关文章
|
1月前
|
开发框架 JavaScript .NET
asp.net中条件查询+分页
asp.net中条件查询+分页
16 1
|
3月前
|
SQL 存储 关系型数据库
sql语句,索引,视图,存储过程
sql语句,索引,视图,存储过程
30 0
|
3月前
|
存储 SQL 缓存
4.2.1 SQL语句、索引、视图、存储过程
4.2.1 SQL语句、索引、视图、存储过程
|
1月前
|
存储 SQL 数据库
sql serve存储过程
sql serve存储过程
14 0
|
1月前
|
存储 SQL
物料清单应用输入模板的SQL存储过程设计
物料清单应用输入模板的SQL存储过程设计
|
2月前
|
SQL 人工智能 运维
数据库基础入门 — SQL排序与分页
数据库基础入门 — SQL排序与分页
25 0
|
3月前
|
存储 SQL Oracle
PL/SQL存储过程的使用
PL/SQL存储过程的使用
67 1
|
4月前
|
存储 SQL Oracle
|
4月前
|
存储 SQL 数据库
数据库第十二次作业 存储过程(PL/SQL语句集)的应用
数据库第十二次作业 存储过程(PL/SQL语句集)的应用
31 0
|
4月前
|
SQL Java 数据库连接
动态sql和分页下(mybatis的分页及特殊字符)
动态sql和分页下(mybatis的分页及特殊字符)
33 0