SQL Server 2005 中的数据分页仅返回 1(一)行

问题描述 投票:0回答:1

有人可以帮助我吗?

我有一个用于 SQL Server 2005 中数据分页的存储过程(见下文)。存储过程的目的是返回特定类别 (CatID) 的产品页面(prodid、描述)。

当我执行存储过程时:

EXEC @return_value = [dbo].[ecosys_CNET_GetCategoryProducts]  
@CatID = N'AA',  
@PageNumber = 1,  
@ProductsPerPage = 10,  
@HowManyProducts = @HowManyProducts OUTPUT 

即使有很多产品,它也只返回一 (1) 行:

@HowManyProducts: 10034

我有一个类似的存储过程,它适用于较小的数据集。 我是否达到了某种极限?

set ANSI_NULLS ON  
set QUOTED_IDENTIFIER ON  
go  

CREATE PROCEDURE [dbo].[ecosys_CNET_GetCategoryProducts]  

(  
@CatID char(2),  
@PageNumber INT,  
@ProductsPerPage INT,  
@HowManyProducts INT OUTPUT  
)  

AS  

-- Declare a new @Products TABLE variable.  
DECLARE @Products TABLE  
(  
RowNumber INT,  
prodid VARCHAR(40),  
description VARCHAR(2000)  
)  

-- Populate the @Product TABLE variable with the selected Products.  
INSERT INTO @Products  

SELECT  

ROW_NUMBER() OVER (ORDER BY cds_atr.prodid),  
cds_atr.prodid,  
cds_stdnee.description  

FROM cds_stdnee  

JOIN cds_atr  
ON (cds_stdnee.prodid = cds_atr.prodid)  

WHERE cds_atr.catid = @CatID  

-- Return the Total Number of Products using an OUTPUT variable.  
SELECT @HowManyProducts = COUNT(prodid) FROM @Products  

-- Extract the Requested Page of Products.  
SELECT DISTINCT prodid, description  

FROM @Products  

WHERE RowNumber > (@PageNumber - 1) * @ProductsPerPage  
  AND RowNumber <= @PageNumber * @ProductsPerPage
pagination sql-server-2005
1个回答
1
投票

如果只返回一行,则很可能只返回一行。添加

SELECT * FROM @Products
并查看其中有哪些行。特别是查看行号。

© www.soinside.com 2019 - 2024. All rights reserved.