create proc blog_getpageableentriesbycategoryid
(@blogid int,
@categoryid int,
@pageindex int,
@pagesize int,
@posttype int,
@sortdesc bit)as
declare @pagelowerbound int
declare @pageupperbound int
--1.由@pageindex和@pagesize算出臨時表中tempid邊界
set @pagelowerbound = @pagesize * @pageindex - @pagesize
set @pageupperbound = @pagelowerbound + @pagesize + 1
-- ? only posts ?
create table #temppagedentryids
(tempid int identity (1, 1) not null,
entryid int not null
) --2.選出符合@posttype與@categoryid的blogid,放入臨時表,並根據@sortdesc排序
if not (@sortdesc = 1)
begin
insert into #temppagedentryids (entryid)
select blog.[id]
from blog_content blog
inner join blog_links links on (blog.[id] = links.postid)
inner join blog_linkcategories cats on (links.categoryid =
cats.categoryid)
where blog.blogid = @blogid
and blog.posttype = @posttype
and cats.categoryid = @categoryid
order by blog.[id]
endelse
begin
insert into #temppagedentryids (entryid)
select blog.[id]
from blog_content blog
inner join blog_links links on (blog.[id] = links.postid)
inner join blog_linkcategories cats on (links.categoryid =
cats.categoryid)
where blog.blogid = @blogid
and blog.posttype = @posttype
and cats.categoryid = @categoryid
order by blog.[id] desc --注意該行
end--3.根據邊界@pagelowerbound與@pageupperbound選擇返回的記錄
select content.blogid,
content.[id],
content.title,
content.dateadded,
content.[text],
content.[description],
content.sourceurl,
content.posttype,
content.author,
content.email,
content.sourcename,
content.dateupdated,
content.titleurl,
content.feedbackcount,
content.parentid,
content.postconfig,
content.entryname,
vc.webcount,
vc.aggcount,
vc.weblastupdated,
vc.agglastupdated
from blog_content content
inner join #temppagedentryids tmp on (content.[id] = tmp.entryid)
left join blog_entryviewcount vc on (content.[id] = vc.entryid and vc.blogid = @blogid)
where content.blogid = @blogid and
tmp.tempid > @pagelowerbound and
tmp.tempid < @pageupperbound
order by tmp.tempid
--4.刪除表
drop table #temppagedentryids
--5.返回符合條件的總記錄數(個人覺得返回刪除的臨時表的總數也是不錯的)
select count(blog.[id]) as totalrecords
from blog_content blog
inner join blog_links links on (blog.[id] = links.postid)
inner join blog_linkcategories cats on (links.categoryid = cats.categoryid)
where blog.blogid = @blogid
and blog.posttype = @posttype
and cats.categoryid = @categoryid
go
4 3分頁儲存管理
1.頁面的概念 記憶體劃分成多個小單元,每個單元k大小,稱 物理 塊。作業也按k單位大小劃分成片,稱為頁面。2.頁表的概念 為了找到被離散分配到記憶體中的作業,記錄每個作業各頁對映到哪個物理塊,形成的頁面對映表,簡稱頁表。頁表的作用 頁號到物理塊號的位址對映 3.位址的處理 作業相對位址在分頁下不同...
Asp Sqlserver2005 分頁儲存過程
t sql set ansi nulls on set quoted identifier on goalter procedure dbo product page rowstotal int output,輸出總記錄數 tablenames varchar 1000 表名,可以是多個表,但不能用...
改進的效率較高的sql2000分頁儲存過程
create procedure dbo test student add the parameters for the stored procedure here id nvarchar 20 學生編號 startrowindex int,起始頁 從0開始 maximumrows int 最大行 ...