Matt Can Code  

1.生成临时表,
CREATE  TABLE #tblPK(
           PK ' + @type + ' NOT NULL ,
           [Sequence] [int] IDENTITY (1, 1) NOT NULL)
INSERT #tblPK (PK)
SELECT '  + @PK + ' FROM ' + @Tables + @strFilter + ' ' + @strGroup + ' ORDER BY ' + @Sort + '
把排序好了的数据表的主键插入其中,并使临时表自动生成序列号

2.根据传进来的页数计算需要提取的记录序号
SET @strPageSize = CAST(@PageSize AS varchar(50))
SET @strStartRow = CAST(((@PageNumber - 1)*@PageSize + 1) AS varchar(50))
SET @strEndRow = CAST(((@PageNumber - 1)*@PageSize + @PageSize) AS varchar(50))

3.合并查询
SELECT ' + @Fields + ' FROM ' + @Tables + ' JOIN #tblPK  ON ' + @PK + ' = #tblPK.PK ' + @strFilter1+ ' ' + @strGroup + ' ORDER BY ' + @Sort


/Files/Mattcoder/Paging.rar

 

posted on 2007-02-12 09:13  Matt Yeung  阅读(635)  评论(0编辑  收藏  举报