用于列出今日最新贴的。
有个想不明的问题是为什么
Declare @SqlText Varchar(1000)
声明为1000个字符大了,但超过255字符之后exec(@SqlText)就会出错。
自动把后面的cut掉了?
ALTER PROCEDURE bbsListNewToday
@curPage int = 0, --当前页
@PageSize int = 30--每页记录数
--@ForumID varchar(4) ='',--每页记录数
--@condition varchar(200)='',
--@tolRecord int output ado.command对象返回记录集时就不能用输出参数了
AS
begin
set nocount on
declare @StartRecord int
declare @EndRecord int
Declare @SqlText Varchar(1000)
Declare @selCol Varchar(1000)
Declare @fcondition varchar(1000)
Declare @sPageSize varchar(10)
Declare @tolRecord int
if @curPage>0
begin
set @curPage = @curPage-1
end
set @StartRecord = @curPage * @PageSize
set @EndRecord = (@curPage +1 ) * @PageSize
set @fcondition=' where boards.[user]=bbs.owner '
set @sPageSize = CAST( @PageSize AS varchar(30))
--select len(@condition)
--返回总贴数
set @tolRecord=(select sum(totalCount) from boards)
--set @SqlText ='select top '+ CAST( @pageSize AS varchar(30)) +' * from bbs order by id desc'
set @selCol = N' bbs.[id] bbsid,TopID,[Owner] boardID,Layer,Click,[Time] postTime,Topic,bbs.[Name] poster,TxtLong,Face,IsBest,IsTop,subject boardName'
if @curPage=0
begin
set @SqlText ='select top '+@sPageSize +' '+CAST( @tolRecord AS varchar(10))+' as tolRecord,'+ @selCol+' from bbs,boards ' + @fcondition+' order by bbsid desc'
end
else
begin
set @SqlText ='select '+CAST( @tolRecord AS varchar(10))+' as tolRecord,* from( select top '+CAST( @sPageSize AS varchar(10))+' * from( select top '+CAST( @EndRecord AS varchar(10))+@selCol+' from bbs,boards '+@fcondition+' order by bbsid desc ) a order by bbsid ) b order by bbsid desc'
end
exec(@SqlText)
set nocount off
end
GO