首页 新闻 会员 周边

谁能给个功能强大的SQL分页存储过程

0
悬赏园豆:20 [已解决问题] 解决于 2013-03-18 20:14

网上找了很多都是对单表实现的,有没有分页存储过程可以满足下面的功能

1.对where 条件参数化

2.支持多表查询,比如select id,name from A union select id,name from B

happydaily的主页 happydaily | 菜鸟二级 | 园豆:301
提问于:2013-03-07 19:48
< >
分享
最佳答案
0

各个版本的都有:http://www.cyqdata.com/cyqdata/article-detail-37508

收获园豆:20
路过秋天 | 老鸟四级 |园豆:4787 | 2013-03-12 03:10
其他回答(4)
0

多表查询就用视图。

geass.. | 园豆:1821 (小虾三级) | 2013-03-08 09:07
0

分页存储过程加多表查询

CREATE PROC LoadPageData
@pageIndex int,
@pageSize int ,
@totalCount int output
as
select * into #Temp from(
SELECT B.*,P.ProjectName,BR.BranchName,U.UName FROM BuildingInfo AS B
LEFT JOIN ProjectInfo AS P ON B.ProjectId = P.Id
LEFT JOIN Branch AS BR ON BR.Id=P.BranchId
LEFT JOIN UserInfo AS U ON P.SubBy=U.Id) as d
--select * from #Temp

declare @str nvarchar(1000);
set @str= N'select top('+CAST(@pageSize as nvarchar(30))+') * from #Temp as T where T.Id not in (select top('+cast((@pageSize*(@pageIndex-1)) as nvarchar(30))+') Id from #Temp as P order by P.Id) order by T.Id'
print @str
exec (@str)
drop table #Temp

Invictus | 园豆:76 (初学一级) | 2013-03-08 09:16
0

可以参考一下我的博客:

 

      http://www.cnblogs.com/hanyinglong/archive/2011/12/09/wdqaq.html

Kencery | 园豆:357 (菜鸟二级) | 2013-03-08 09:28
0

http://www.cnblogs.com/aehyok/archive/2012/12/04/2800881.html你可以试试这个,好好看看其实很简单,SQL Server 自带的,你自己封装成存储过程就可以了

aehyok | 园豆:1212 (小虾三级) | 2013-03-12 12:04
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册