SQL2000版: Create proc [dbo].[proc_viewlist] @Id varchar(50), --标识ID @Table varchar(100), --表名 @Where varchar(7500),--查询条件 @Column varchar(300),--查询的列,查询全部用* @NewPageIndex varchar(10),--当前页码 @PageSize varchar(10), --分页条数 @order varchar(50) --排序列 as declare @str varchar(8000) set @str=' set nocount on begin declare @indextable table(_id int identity(1,1),nid int) declare @PageLowerBound int declare @PageUpperBound int set @PageLowerBound=('+@NewPageIndex+'-1)*'+@PageSize+' set @PageUpperBound=@PageLowerBound+'+@PageSize+' insert into @indextable(nid) select '+@id+' from '+@table if len(@where)<>0 set @str=@str+' where '+@where+' select count(1) from @indextable select '+@Column+' from '+@table+' ,@indextable t where '+@table+'.'+@id+'=t.nid and t._id between @PageLowerBound+1 and @PageUpperBound order by '+@order+' end set nocount off ' exec(@str) print(@str) SQL2005版: Create proc [dbo].[proc_viewlist] @Table varchar(100), --表名 @Where varchar(7500),--查询条件 @Column varchar(300),--查询的列,查询全部用* @NewPageIndex int,--当前页码 @PageSize int,--分页条数 @order varchar(50) --排序列 as declare @str varchar(8000) set @str='select count(1) from '+@table if len(@where)<>0 set @str=@str+' where '+@where set @str=@str+' select * from ( select row_number() over(order by '+@order+') as Rownum, '+@Column+' from '+@table if len(@where)<>0 set @str=@str+' where '+@where set @str=@str+' )T where Rownum between '+cast((@NewPageIndex-1)*@PageSize+1 as varchar(20))+' and '+cast(@NewPageIndex*@PageSize as varchar(20)) set @str=@str+' order by '+@order exec(@str) print(@str)