由于数据量比较大,需对报表and图表进行分页。
那位大侠有这样的存储过程或者什么算法。
可以大话,给我一个。
email:John_Yao@dlink.com.cn
msn:382364278@live.cn
------解决方案--------------------------------------------------------
- SQL code
select top 20 from table where table_id not in (select top 20 table_id from table )
------解决方案--------------------------------------------------------
create PROCEDURE GetCardsPage
@PageIndex INT,
@PageSize INT,
@RecordCount INT ,
@PageCount INT
AS
SELECT @RecordCount = COUNT(*) FROM cards
SET @PageCount = CEILING(@RecordCount * 1.0 / @PageSize)
DECLARE @SQLSTR NVARCHAR(1000)
IF @PageIndex = 0 OR @PageCount <= 1
SET @SQLSTR =N'SELECT TOP '+STR( @PageSize )+
' * FROM cards ORDER BY cardId DESC'
ELSE IF @PageIndex = @PageCount - 1
SET @SQLSTR =N' SELECT * FROM ( SELECT TOP '+STR( @RecordCount - @PageSize * @PageIndex )+
' * FROM cards ORDER BY cardId ASC ) TempTable ORDER BY cardId DESC'
ELSE
SET @SQLSTR =N' SELECT TOP '+STR( @PageSize )+' * FROM ( SELECT TOP '+STR( @RecordCount - @PageSize * @PageIndex )+
' * FROM cards ORDER BY cardId ASC ) TempTable ORDER BY cardId DESC'
EXEC (@SQLSTR)
------解决方案--------------------------------------------------------
网上有很多,搜搜会有新发现