支持多表分页查询的存储过程

本文转载:http://hi.baidu.com/hanrenjun/item/caa393dc811efbdd251f40ad

              http://www.bhcode.net/article/20081229/3796.html

同样不错的博客:http://blog.csdn.net/lyq5655779/article/details/7328560#

 

usp_PagingLarge测试脚本:

USE [Northwind]
GO

--SQL语句
SELECT  Orders.OrderID ,
        Products.ProductName AS 'Name'
FROM    dbo.Orders INNER JOIN dbo.[Order Details] ON Orders.OrderID = [Order Details].OrderID INNER JOIN dbo.Products ON [Order Details].ProductID = Products.ProductID
ORDER BY Orders.OrderID desc,
        Products.ProductName  asc    
        
/*

  AAAA   AAAA   AAAA   AAAA  RRRRR   GGGG  HH  HH  ######
 AA  AA AA  AA AA  AA AA  AA RR  RR GG  GG HH  HH  ######
 AA  AA AA  AA AA  AA AA  AA RR  RR GG     HH  HH   ####
 AAAAAA AAAAAA AAAAAA AAAAAA RRRRR  GG GGG HHHHHH    ##
 AA  AA AA  AA AA  AA AA  AA RR  RR GG  GG HH  HH
 AA  AA AA  AA AA  AA AA  AA RR  RR  GGG G HH  HH    ##

*/


DECLARE	@return_value int

EXEC	@return_value = [dbo].[usp_PagingLarge]
		@TableNames = N'dbo.Orders INNER JOIN dbo.[Order Details] ON Orders.OrderID = [Order Details].OrderID INNER JOIN dbo.Products ON [Order Details].ProductID = Products.ProductID',
		@PrimaryKey = N'Orders.OrderID',
		@Fields = N'Orders.OrderID ,Products.ProductName as Name',
		@PageSize = 20,
		@CurrentPage = 2,
		@Filter = NULL,
		@Group = NULL,
		@Order = N'Orders.OrderID desc,Products.ProductName  asc'


GO

  

proc_ListPage测试脚本:

USE [Northwind]
GO

--SQL语句
SELECT  Orders.OrderID ,
        Products.ProductName
FROM    dbo.Orders INNER JOIN dbo.[Order Details] ON Orders.OrderID = [Order Details].OrderID INNER JOIN dbo.Products ON [Order Details].ProductID = Products.ProductID
ORDER BY Orders.OrderID desc,
        Products.ProductName  asc      
        

/*

  AAAA   AAAA   AAAA   AAAA  RRRRR   GGGG  HH  HH  ######
 AA  AA AA  AA AA  AA AA  AA RR  RR GG  GG HH  HH  ######
 AA  AA AA  AA AA  AA AA  AA RR  RR GG     HH  HH   ####
 AAAAAA AAAAAA AAAAAA AAAAAA RRRRR  GG GGG HHHHHH    ##
 AA  AA AA  AA AA  AA AA  AA RR  RR GG  GG HH  HH
 AA  AA AA  AA AA  AA AA  AA RR  RR  GGG G HH  HH    ##

*/

DECLARE	@return_value int,
		@pageCount int,
		@Counts int

EXEC	@return_value = [dbo].[proc_ListPage]
		@tblName = N'dbo.Orders INNER JOIN dbo.[Order Details] ON Orders.OrderID = [Order Details].OrderID INNER JOIN dbo.Products ON [Order Details].ProductID = Products.ProductID',
		@fldName = N'[orders].orderID,Products.ProductName',
		@pageSize = 20,
		@page = 2,
		@pageCount = @pageCount OUTPUT,
		@Counts = @Counts OUTPUT,
		@fldSort = N'[orders].orderID desc,Products.ProductName',
		@Sort = 0,--如果@fldSort字段为NULL,则@Sort也为null。
		@strCondition = NULL,
		@ID = N'Orders.OrderID',
		@Dist = 0

SELECT	@pageCount as N'@pageCount',
		@Counts as N'@Counts'


GO

  

 


  • 比较麻烦,把他记录下来。
    前台UI:

本文转载:http://www.cnblogs.com/xiachufeng/archive/2010/07/30/1788592.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值