当前位置:数据库 > SQLServer >>

SqlServer 多表查询分页

帮忙针对这个查询结果集 写一个分页的 存储过程 select a.*,b.img_typename from jingwailife a,jingwaiimgtype b where a.img_type=b.img_typecode and a.img_type='1' order by img_date desc
答案:if (object_id('pro', 'P') is not null) 
drop proc pro
go
create procedure pro  
@pageIndex int,   
@pageSize int
as    
declare @startRow int, @endRow int    
set @startRow = (@pageIndex - 1) * @pageSize +1    
set @endRow = @startRow + @pageSize -1   
select * from (    
select a.*,b.img_typename from jingwailife a,jingwaiimgtype b ,row_number() over (order by sno asc) as number 
where a.img_type=b.img_typecode
 and a.img_type='1'  ) t   
 where t.number between @startRow and @endRow
go
exec pro @pageIndex ,  @pageSize 
go
其他:多表查询分页的话,我认为最好还是用视图 这个真不会啊   加油把 我是来真惊艳的 

上一个:SQLSERVER 2005 执行全文查询失败。"服务没有运行。",怎么回事
下一个:JDBC驱动连接。下载JDBC驱动三个文件mssqlserver.jar、msutil.jar和msbase.jar具体在哪?

Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,