【发布时间】:2018-09-12 16:26:30
【问题描述】:
我在 SQL 服务器上创建了一个 SP:
CREATE PROC [dbo].[proc_GetSalesProductWise] @ItemCode int,
@year int,
@CustomerCode numeric(18,0),
@Month int,
@DataFrom nvarchar(15) AS
BEGIN
SELECT ISNULL((SELECT SUM(Quantity)
FROM QryBoutiqueSalesGraphProductWise
WHERE ItemCode = CASE WHEN ISNULL(@ItemCode,0)=0 THEN ItemCode
ELSE @ItemCode
END
AND YEAR(InvDate) = @year
AND Month(InvDate) = @Month
AND DataFrom = @DataFrom
AND CustomerCode = @CustomerCode
GROUP BY ItemCode),0) AS Quantity,
ISNULL((SELECT SUM(GrossAmount)
FROM QryBoutiqueSalesGraphProductWise
WHERE ItemCode = CASE WHEN ISNULL(@ItemCode,0)=0 THEN ItemCode
ELSE @ItemCode
END
AND YEAR(InvDate) = @year
AND Month(InvDate) = @Month
AND DataFrom = @DataFrom
AND CustomerCode = @CustomerCode
GROUP BY ItemCode),0) AS Amount
END
它在 Localhost 上运行良好,但在实时站点上出现以下错误。
System.Data.SqlClient.SqlException: Subquery returned more than 1 value.
This is not permitted when the subquery follows =, !=, <, <= , >, >= or when
the subquery is used as an expression.
谁能帮我解决这个问题或告诉我问题出在哪里?
【问题讨论】:
-
您使用的是 MySQL 还是 MS SQL Server?
-
错误的哪一部分你不明白?这很清楚(在我看来)。
-
程序有问题吗?
-
jarlh 我正在使用 SQL Server
-
如果所选数据的同一年、同一月和“客户代码”存在多个“项目代码”,您将收到错误消息。对于所选数据,此数据条件显然不存在于您的非产品环境中。您可以使用
SELECT ItemCode, year(InvDate) AS year, Month(InvDate) AS month, CustomerCode FROM QryBoutiqueSalesGraphProductWise GROUP BY ItemCode, year(InvDate), Month(InvDate), CustomerCode HAVING COUNT(*) > 1;识别问题数据
标签: sql sql-server sql-server-2008 stored-procedures