封装成存储过程,但是有点小问题,如果有弄好了的朋友可留言,谢谢了,我只提供了一个模版哈(也是我想实现的功能)
create procedure paging_procedure
( @pageIndex int, -- 第几页
@pageSize int, -- 每页包含的记录数
@moreTable text,--查询哪个表(支持多表链接查询)
@orderBy varchar(200),--排序的字段
@isAD varchar(100)-- asc还是desc排序
)
as
begin
select top (select @pageSize) *
from (select row_number() over(order by @orderBy @isAD) as rownumber,*
from @tabName) temp_row
where rownumber>(@pageIndex-1)*@pageSize;
end
写成sql语句,里面的参数表示什么意思,请参照上面的存储过程
select top (select 2) *
from (select row_number() over(order by ID asc) as rownumber,*
from SysError) temp_row
where rownumber>(2)*2
表结构
CREATE TABLE [dbo].[SysError](
[ID] [int] IDENTITY(1,1) NOT NULL,
[ErrorContent] [ntext] NULL,
[ErrorTime] [datetime] NULL,
[Ipaddress] [nvarchar](200) NULL,
[ShopID] [int] NULL,
[UserID] [int] NULL,
[ErrorType] [nvarchar](50) NULL,
CONSTRAINT [PK_SysError] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]