--分页,短消息。
CREATE PROCEDURE [a_mail_page]
(@pagesize int,
@pageindex int,
@docount bit,
@userid int,
@box int)
as
set nocount on
declare @indextable table(id int identity(1,1),nid int)
declare @PageLowerBound int
declare @PageUpperBound int
if(@box=1) --@box 1代表收件箱,@box 2代表发件箱
begin
if(@docount=1)
select count(mailid)
from vd_mailinbox
where touserid = @userid and touse=1 --fromuse=1表示没有删除
else
begin
set @PageLowerBound=(@pageindex-1)*@pagesize
set @PageUpperBound=@PageLowerBound+@pagesize
set rowcount @PageUpperBound
insert into @indextable(nid)
select mailid from vd_mailinbox
where touserid = @userid and touse=1 order by mailid desc
select O.mailid, O.crdate, O.username , O.remind, O.title
from vd_mailinbox O,@indextable t
where O.mailid=t.nid
and t.id>@PageLowerBound and t.id<=@PageUpperBound order by t.id
end
end
else
begin
if(@docount=1)
select count(mailid) from vd_mailOutbox
where fromuserid = @userid and fromuse=1 --fromuse=1表示没有删除
else
begin
set @PageLowerBound=(@pageindex-1)*@pagesize
set @PageUpperBound=@PageLowerBound+@pagesize
set rowcount @PageUpperBound
insert into @indextable(nid) select mailid from vd_mailoutbox where fromuserid=@userid and fromuse=1 order by mailid desc
select O.mailid, O.crdate, O.username , O.remind, O.title from vd_mailOutbox O,@indextable t where O.mailid=t.nid
and t.id>@PageLowerBound and t.id<=@PageUpperBound order by t.id
end
end