CREATE procedure main_table_pwqzc
(@pagesize int
@pageindex int
@docount bit
@this_id)
as
if(@docount=
begin
select count(id) from luntan where this_id=@this_id
end
else
begin
declare @indextable table(id int identity(
declare @PageLowerBound int
declare @PageUpperBound int
set @PageLowerBound=(@pageindex
set @PageUpperBound=@PageLowerBound+@pagesize
set rowcount @PageUpperBound
insert into @indextable(nid) select id from luntan where this_id=@this_id order by reply_time desc
select a
and t
end
GO
存儲過程會根據傳入的參數@docount來確定是不是要返回所有要分頁的記錄總數
特別是這兩行
set rowcount @PageUpperBound
insert into @indextable(nid) select id from luntan where this_id=@this_id order by reply_time desc
真的是妙不可言!!set rowcount @PageUpperBound當記錄數達到@PageUpperBound時就會停止處理查詢
and t
而這句也只從表中取出所需要的記錄
妙啊
CREATE PROCEDURE Paging_RowCount
(
@Tables varchar(
@PK varchar(
@Sort varchar(
@PageNumber int =
@PageSize int =
@Fields varchar(
@Filter varchar(
@Group varchar(
AS
/*Default Sorting*/
IF @Sort IS NULL OR @Sort =
SET @Sort = @PK
/*Find the @PK type*/
DECLARE @SortTable varchar(
DECLARE @SortName varchar(
DECLARE @strSortColumn varchar(
DECLARE @operator char(
DECLARE @type varchar(
DECLARE @prec int
/*Set sorting variables
IF CHARINDEX(
BEGIN
SET @strSortColumn = REPLACE(@Sort
SET @operator =
END
ELSE
BEGIN
IF CHARINDEX(
SET @strSortColumn = REPLACE(@Sort
SET @operator =
END
IF CHARINDEX(
BEGIN
SET @SortTable = SUBSTRING(@strSortColumn
SET @SortName = SUBSTRING(@strSortColumn
END
ELSE
BEGIN
SET @SortTable = @Tables
SET @SortName = @strSortColumn
END
SELECT @type=t
FROM sysobjects o
JOIN syscolumns c on o
JOIN systypes t on c
WHERE o
IF CHARINDEX(
SET @type = @type +
DECLARE @strPageSize varchar(
DECLARE @strStartRow varchar(
DECLARE @strFilter varchar(
DECLARE @strSimpleFilter varchar(
DECLARE @strGroup varchar(
/*Default Page Number*/
IF @PageNumber <
SET @PageNumber =
/*Set paging variables
SET @strPageSize = CAST(@PageSize AS varchar(
SET @strStartRow = CAST(((@PageNumber
/*Set filter & group variables
IF @Filter IS NOT NULL AND @Filter !=
BEGIN
SET @strFilter =
SET @strSimpleFilter =
END
ELSE
BEGIN
SET @strSimpleFilter =
SET @strFilter =
END
IF @Group IS NOT NULL AND @Group !=
SET @strGroup =
ELSE
SET @strGroup =
/*Execute dynamic query*/
EXEC(
DECLARE @SortColumn
SET ROWCOUNT
SELECT @SortColumn=
SET ROWCOUNT
SELECT
)
GO
From:http://tw.wingwit.com/Article/program/Oracle/201311/17031.html