Create PROCEDURE ALLGetPageDataOutRowPageCount
(
@PageIndex int = 1,--当前页数
@PageSize int = 4,--每页大小
@NowPage int = 1,--根据传入栏目id要加载当前页的数据
@NowTable NVARCHAR(50) = N'table',--当前传入表名
@RowCount int output,--总行数(传出参数)
@PageCount int output--总页数(传出参数)
)
AS
begin
DECLARE @sql NVARCHAR(max),@sqlCount NVARCHAR(225)
select @RowCount =COUNT(FChildId),@PageCount=CEILING((COUNT(FChildId)+0.0)/@PageSize) FROM @NowTable where FParentsId=@NowPage
SET @sql='SELECT TOP '+LTRIM(str(@PageSize))+' * FROM '+@NowTable+' where FParentsId='+LTRIM(str(@NowPage))+' and FChildId not in(select top '+LTRIM(str((@PageIndex-1)*@PageSize))+' FChildId from '+@NowTable+' where FParentsId='+LTRIM(str(@NowPage))+' order by FImagIndex desc,FImageUpTime desc)order by FImagIndex desc, FImageUpTime desc'
print @sql
EXEC(@sql)
end
Create PROCEDURE ALLGetPageDataOutRowPageCount
(
@PageIndex int = 1,--当前页数
@PageSize int = 4,--每页大小
@NowPage int = 1,--根据传入栏目id要加载当前页的数据
@NowTable NVARCHAR(50) = N'table',--当前传入表名
@RowCount int output,--总行数(传出参数)
@PageCount int output--总页数(传出参数)
)
AS
begin
DECLARE @sql NVARCHAR(max),@sqlCount NVARCHAR(225)
--拼接动态sql语句
declare @strs varchar(Max)=
'select'+ @RowCount+' =COUNT(FChildId),'+@PageCount+'=CEILING((COUNT(FChildId)+0.0)/'+@PageSize+') FROM'+ @NowTable+' where FParentsId='+@NowPage
--调用存储过程执行sql语句
exec(@strs)
SET @sql='SELECT TOP '+LTRIM(str(@PageSize))+' * FROM '+@NowTable+' where FParentsId='+LTRIM(str(@NowPage))+' and FChildId not in(select top '+LTRIM(str((@PageIndex-1)*@PageSize))+' FChildId from '+@NowTable+' where FParentsId='+LTRIM(str(@NowPage))+' order by FImagIndex desc,FImageUpTime desc)order by FImagIndex desc, FImageUpTime desc'
print @sql
EXEC(@sql)
end
go