论坛中展示某模块的帖子信息

本文详细介绍了如何使用SQL进行模块帖子主题的分页查询及联表输出,包括创建表变量、分页输出、联表查询等关键步骤,确保了查询结果的准确性和效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ExpandedBlockStart.gif代码
USE [WebE]
GO
/****** 对象:  StoredProcedure [dbo].[P_FPosts_ModulePostsOutput]    脚本日期: 07/29/2010 20:43:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


--某模块的帖子主题
CREATE Procedure [dbo].[P_FPosts_ModulePostsOutput] 
@ModuleID varchar(10),
@PageSize int,
@Page int 
 
As
--Step 1  创建表变量 
--
所有分页筛选后的POSTID
declare @ZModulePosts_AllInfo_Temp Table
(
PostID  
varchar(10),
ModuleID 
varchar(10) ,
RowNumber 
bigint
) ;

--Step 2 分页输出
--
定义第一行记录
declare @firstRow int;
--定义最后一条记录
declare @lastRow int;--设置第一条记录
set @firstRow=((@Page-1)*@PageSize)+1;
--设置最后一条记录
set @lastRow=@firstRow+@PageSize;--定义查询SQL字段
 
insert into @ZModulePosts_AllInfo_Temp
select * from 
(  
select ForumPostID.PostID,ForumPostID.ModuleID, Row_Number() over(  order by PostID Descas RowNumber  from ForumPostID 
where ForumPostID.ModuleID=@ModuleID
as TB 
where  TB.RowNumber>=@firstRow and TB.RowNumber<@lastRow  

----------------分页输出完毕--------

--Step 3 联表输出
 select ForumPosts.PostID,ForumPosts.Title,ForumPosts.ModuleID,ForumModules.[Name] , ForumPosts.UserName,ForumPosts.PubTime,ForumPosts.LastReplier,ForumPosts.LastReplyTime,ForumPosts.IsDelete,ForumPosts.IsLock  
from  ForumPosts ,ForumModules ,@ZModulePosts_AllInfo_Temp as ZMAT
where  
  ZMAT.PostID
=ForumPosts.PostID
and ForumModules.ModuleID = @ModuleID
and ForumPosts.IsDelete=0 --筛选已删除的
Order by PostID desc
  


 




数据库表冗余存储+PostID表+分页

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值