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

 
 


相关文章
|
29天前
|
开发框架 JavaScript .NET
asp.net中条件查询+分页
asp.net中条件查询+分页
15 1
|
3月前
|
SQL 存储 关系型数据库
sql语句,索引,视图,存储过程
sql语句,索引,视图,存储过程
29 0
|
6月前
|
存储
SQLServer分页获取数据的存储过程
SQLServer分页获取数据的存储过程
24 0
|
6月前
|
存储 开发框架 前端开发
基于MySQL 实现通用分页存储过程(下篇-超详细)(上)
基于MySQL 实现通用分页存储过程(下篇-超详细)
65 0
|
3月前
|
存储 SQL 缓存
4.2.1 SQL语句、索引、视图、存储过程
4.2.1 SQL语句、索引、视图、存储过程
|
28天前
|
存储 SQL 数据库
sql serve存储过程
sql serve存储过程
14 0
|
1月前
|
存储 SQL
物料清单应用输入模板的SQL存储过程设计
物料清单应用输入模板的SQL存储过程设计
|
3月前
|
存储 SQL Oracle
PL/SQL存储过程的使用
PL/SQL存储过程的使用
65 1
|
4月前
|
存储 SQL Oracle
|
9月前
|
存储 SQL 安全
数据库SQL Server 9-10 章(存储过程与触发器)
数据库SQL Server 9-10 章(存储过程与触发器)
150 0