日期:2014-05-17 浏览次数:20465 次
USE [Fruitnet]
GO
/****** Object: StoredProcedure [dbo].[G_Paging_MultiTable] Script Date: 04/19/2013 11:02:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/**
* --调用例子:
* -- 1.单表/单排序
* EXEC G_Paging_MultiTable 'bigtable','d_id','d_id,d_title,d_content,d_time',20,1,'','','d_id desc'
* -- 2.单表/多排序
* EXEC G_Paging_MultiTable 'bigtable','d_id','*',20,0,'','','d_time asc,d_id desc'
* -- 3.多表/单排序
* EXEC G_Paging_MultiTable 'bigtable left join bigtable_author on bigtable.d_id=bigtable_author.BigTable_id', 'bigtable.d_id', 'bigtable.d_id,bigtable.d_title,bigtable.d_content,bigtable.d_time,bigtable_author.d_author', 20, 0, '', '', 'bigtable.d_id asc'
* -- 4.多表/多排序
* EXEC G_Paging_MultiTable 'bigtable left join bigtable_author on bigtable.d_id=bigtable_author.BigTable_id', 'bigtable.d_id', 'bigtable.d_id,bigtable.d_title,bigtable.d_content,bigtable.d_time,bigtable_author.d_author', 20, 0, '', '', 'bigtable.d_time asc,bigtable.d_id desc'
*/
ALTER PROCEDURE [dbo].[G_Paging_MultiTable]
@TableNames VARCHAR(200), -- 表名,可以是多个表,但不能用别名
@PrimaryKey VARCHAR(100), -- 主键,可以为空,但@Order为空时该值不能为空
@Fields VARCHAR(200), -- 要取出的字段,可以是多个表的字段,可以为空,为空表示select *
@PageSize INT, -- 每页记录数
@CurrentPage INT, -- 当前页,0表示第1页
@Filter VARCHAR(200) = '', -- 条件,可以为空,不用填 where
@Group VARCHAR(200) = '', -- 分组依据,可以为空,不用填 group by
@Order VARCHAR(200) = '' -- 排序,可以为空,为空默认按主键升序排列,不用填 order by
AS
BEGIN
DECLARE @SortColumn VARCHAR(200)
DECLARE @Operator CHAR(2)
DECLARE @SortTable VARCHAR(200)
DECLARE @SortName VARCHAR(200)