首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >SQL Server 2005中的数据分页仅返回1(1)行

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

Stack Overflow用户
提问于 2009-03-31 17:18:00
回答 1查看 300关注 0票数 0

谁能帮帮我。

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

当我执行存储过程时:

代码语言:javascript
运行
复制
EXEC @return_value = [dbo].[ecosys_CNET_GetCategoryProducts]  
@CatID = N'AA',  
@PageNumber = 1,  
@ProductsPerPage = 10,  
@HowManyProducts = @HowManyProducts OUTPUT 

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

代码语言:javascript
运行
复制
@HowManyProducts: 10034

我有一个类似的存储过程,它对较小的数据集工作得很好。我是不是达到了某种极限?

代码语言:javascript
运行
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-03-31 17:23:34

如果它只返回一行,那么很可能只返回一行。添加一个SELECT * FROM @Products并查看其中有哪些行。特别要注意行号。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/702105

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档