sql 分页
-- Region Parameters
declare @pageindex int
set @pageindex=2
set @pagesize=10
DECLARE @p0 Int = ((@pageindex-1)*@pagesize)+1 --11
DECLARE @p1 Int =((@pageindex-1)*@pagesize)+@pagesize --20
@pagesize --10 -- EndRegion SELECT [t1].[CustomerID], [t1].[CompanyName], [t1].[ContactName], [t1].[ContactTitle], [t1].[Address], [t1].[City], [t1].[Region], [t1].[PostalCode], [t1].[Country], [t1].[Phone], [t1].[Fax] FROM ( SELECT ROW_NUMBER() OVER (ORDER BY [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Country], [t0].[Phone], [t0].[Fax]) AS [ROW_NUMBER], [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], [t0].[Country], [t0].[Phone], [t0].[Fax] FROM [Customers] AS [t0] ) AS [t1] WHERE [t1].[ROW_NUMBER] BETWEEN @p0 + AND @p0 + @p1 ORDER BY [t1].[ROW_NUMBER]
分页存储过程 create procedure update
(@pagesize int,
@pageindex int,
@docount bit)
as
if(@docount=)
select count(*) from AAAAA
else
begin
with temptbl as (
SELECT ROW_NUMBER() OVER (ORDER BY ID desc)AS Row, * from AAAAA O )
SELECT * FROM temptbl where Row between (@pageindex-)*@pagesize+ and (@pageindex-)*@pagesize+@pagesize
end