34,838
社区成员




表结构都是如下:
ID PID PValue AddTime
1 1 24 2016-02-02 10:46
2 1 25 2016-02-02 10:47
ID PID PValue AddTime
1 1 20 2016-03-02 10:46
2 1 28 2016-03-03 10:47
....
use tempdb
go
if OBJECT_ID('PageShow','P') is not null
drop procedure PageShow
go
Create procedure PageShow(
@QueryStr nvarchar(4000), --表名、视图名、查询语句
@Where nvarchar(1000)='',--条件
@PageSize int=10, --每页的大小(行数)
@PageCurrent int=1, --要显示的页
@FdShow nvarchar (4000)='', --要显示的字段列表
@FdOrder nvarchar (1000)='' --排序字段列表
)
as
if object_id(@QueryStr) is null
set @QueryStr='('+@QueryStr+')as Tab'
if @Where>''
set @Where=' where '+@Where
if @FdShow=''
set @FdShow='*'
if @FdOrder=''
set @FdOrder='(select 1)'
declare @Str nvarchar(max)
set @Str='select '+@FdShow+' from (select Row=Row_number()over(order by '+@FdOrder+'),'+@FdShow+
' from '+@QueryStr+@Where+') as Tab2 where Row between '+rtrim((@PageCurrent-1)*@PageSize+1)+' and '+rtrim(@PageCurrent*@PageSize)
exec(@Str)
go
exec PageShow @QueryStr='sysobjects',@FdShow='ID,Name',@PageCurrent=2,@Where=' ID>100 '