1个回答
推荐于2017-09-05
展开全部
写存储过程 ..
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER PROCEDURE usp_Province_pagination
@PageSize INT, --每页的显示的行数
@AbsolutePage INT, -- 当前页的页数
@PageCount INT OUTPUT --总页数
AS
DECLARE @BeginRecord INT --记录每此从哪一行开始读取
DECLARE @RecordCount INT --表中数据的总条数
DECLARE @sql NVARCHAR(1000)
SET @RecordCount = (SELECT count(*) FROM Province)
--表中没有数据的情况
IF @RecordCount = 0
BEGIN
SET @PageCount = 0
RETURN(0)
END
-- 表中的总条数大于定义的每页的行数的情况
IF @RecordCount > @PageSize
BEGIN
-- 计算总能分多少页
SET @PageCount = (@RecordCount + @PageSize - 1)/@PageSize
--当前应该从哪一行开始读取
SET @BeginRecord = ((@AbsolutePage-1) * @PageSize)
SET @sql = N'SELECT TOP ' + cast(@PageSize AS NVARCHAR(100)) +' ProvinceID, provinceCode, ProvinceName
FROM Province
WHERE ProvinceID NOT IN
(SELECT TOP '+ CAST(@BeginRecord AS NVARCHAR(100)) + ' ProvinceID
FROM Province)'
EXECUTE sp_executesql @sql
END
ELSE -- -- 表中的总条数大于定义的每页的行数情况
BEGIN
SET @PageCount = 1
SET @SQL = 'SELECT ProvinceID, provinceCode, ProvinceName FROM Province '
EXECUTE sp_executesql @sql
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER PROCEDURE usp_Province_pagination
@PageSize INT, --每页的显示的行数
@AbsolutePage INT, -- 当前页的页数
@PageCount INT OUTPUT --总页数
AS
DECLARE @BeginRecord INT --记录每此从哪一行开始读取
DECLARE @RecordCount INT --表中数据的总条数
DECLARE @sql NVARCHAR(1000)
SET @RecordCount = (SELECT count(*) FROM Province)
--表中没有数据的情况
IF @RecordCount = 0
BEGIN
SET @PageCount = 0
RETURN(0)
END
-- 表中的总条数大于定义的每页的行数的情况
IF @RecordCount > @PageSize
BEGIN
-- 计算总能分多少页
SET @PageCount = (@RecordCount + @PageSize - 1)/@PageSize
--当前应该从哪一行开始读取
SET @BeginRecord = ((@AbsolutePage-1) * @PageSize)
SET @sql = N'SELECT TOP ' + cast(@PageSize AS NVARCHAR(100)) +' ProvinceID, provinceCode, ProvinceName
FROM Province
WHERE ProvinceID NOT IN
(SELECT TOP '+ CAST(@BeginRecord AS NVARCHAR(100)) + ' ProvinceID
FROM Province)'
EXECUTE sp_executesql @sql
END
ELSE -- -- 表中的总条数大于定义的每页的行数情况
BEGIN
SET @PageCount = 1
SET @SQL = 'SELECT ProvinceID, provinceCode, ProvinceName FROM Province '
EXECUTE sp_executesql @sql
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询