CREATE PROC novel_list
@boardid int,
@tbname sysname, --要分页显示的表名
@FieldKey sysname, --用于定位记录的主键(惟一键)字段,只能是单个字段
@PageCurrent int=1, --要显示的页码
@PageSize int=10, --每页的大小(记录数)
@FieldShow nvarchar(1000)= ' ', --以逗号分隔的要显示的字段列表,如果不指定,则显示所有字段
@FieldOrder nvarchar(1000)= ' ', --以逗号分隔的排序字段列表,可以指定在字段后面指定DESC/ASC用于指定排序顺序
@Where nvarchar(1000)= ' ', --查询条件
@PageCount int OUTPUT, --总页数
@RecordCount int OUTPUT
AS
select top 16 topicid,title from novel_commend where boardid=@boardid order by commendid desc
select topicid,title,amount into #order_week from novel_order where boardid=@boardid and datediff(day, dateadd(day, -7, getdate()), times)> =0
select top 15 topicid,title,sum(amount) as amount from #order_week group by topicid,title order by sum(amount) desc
exec novel_page @tbname,@FieldKey,@PageCurrent,@PageSize,@FieldShow,@FieldOrder,@Where,@PageCount output,@RecordCount OUTPUT
GO
高手能给讲解一下最后一句是什么意思吗?
初学存储过程,请不要笑话.
------解决方案--------------------------------------------------------
执行存储过程novel_page ,@tbname,@FieldKey,@PageCurrent,@PageSize,@FieldShow,@FieldOrder,@Where,@PageCount output,@RecordCount OUTPUT
这些是需要的参数,存储过程返回值为@PageCount ,@RecordCount 应该是这样
------解决方案--------------------------------------------------------
--将novel_commend表中符合条件boardid=@boardid的topicid和title记录,按照commendid降序排列。只列出前16条记录。
select top 16 topicid,title from novel_commend where boardid=@boardid order by commendid desc
--将表novel_order中条件符合:boardid=@boardid并且时间在最近7天之内的topicid,title,amount记录插入到临时表#order_week中
select topicid,title,amount into #order_week from novel_order where boardid=@boardid and datediff(day, dateadd(day, -7, getdate()), times)> =0
--从临时表#order_week中按照topicid,title分组检索topicid,title,amount(amount总和)记录,并按照amount总和降序排列结果。只显示前15条记录。
select top 15 topicid,title,sum(amount) as amount from #order_week group by topicid,title order by sum(amount) desc
--执行存储过程novel_page,并传递相应参数
exec novel_page @tbname,@FieldKey,@PageCurrent,@PageSize,@FieldShow,@FieldOrder,@Where,@PageCount output,@RecordCount OUTPUT
大概是这样,不知道表述的你能否看明白?