CREATE procedure GetDetails
(@pagesize int,
@pageindex int,
@docount bit,
@topicid int)
as
set nocount on
declare @Count int
declare @id datetime
if(@docount=1)
return (select count(repostid) from repost)+1
else
begin
if @pageindex>0
begin
set @Count = @pagesize * (@pageindex -1) + 1
set rowcount @Count
select @id=posttime from where posttime in (select posttime from topic where topicid=@topicid union select posttime from repost where topicid=@topicid) order by posttime asc
endset rowcount @pagesize
select topicid,topiccontent,username,posttime from topic where topicid=@topicid union select topicid,repostcontent,username,posttime from repost where topicid=@topicid where posttime >=@id order by posttime ascset rowcount 0
end
set nocount off
GO说明下:我把topic(主题)和repost(回复)分开放两张表,显示主题的时候要合并起来,分页想用上面的存储过程,为什么出错?错误信息:在关键字where附近出错,在关键字where附近出错
(@pagesize int,
@pageindex int,
@docount bit,
@topicid int)
as
set nocount on
declare @Count int
declare @id datetime
if(@docount=1)
return (select count(repostid) from repost)+1
else
begin
if @pageindex>0
begin
set @Count = @pagesize * (@pageindex -1) + 1
set rowcount @Count
select @id=posttime from where posttime in (select posttime from topic where topicid=@topicid union select posttime from repost where topicid=@topicid) order by posttime asc
endset rowcount @pagesize
select topicid,topiccontent,username,posttime from topic where topicid=@topicid union select topicid,repostcontent,username,posttime from repost where topicid=@topicid where posttime >=@id order by posttime ascset rowcount 0
end
set nocount off
GO说明下:我把topic(主题)和repost(回复)分开放两张表,显示主题的时候要合并起来,分页想用上面的存储过程,为什么出错?错误信息:在关键字where附近出错,在关键字where附近出错
^^^^怎么from和where一起了?
这样也不对
select posttime from topic where topicid=@topicid union select posttime from repost where topicid=@topicid不是返回单结果集,
另外order by 前应加个别名 如...) as aaa order by aaa.posttime