我在SQL服务器上创建了一个SP:
Begin Try
--Query 1
End Try
Begin Catch
-- Query 2
End catch
它在Localhost上完美运行,但在实时网站上出现以下错误。
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
任何人都可以帮助我解决这个问题吗?或者告诉我这个问题是什么?
答案 0 :(得分:1)
如果itemcode超过onme,那么大多数SQL查询返回多行的机会是uniq:
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
和
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
请尝试以下方式:
Create Proc [dbo].[proc_GetSalesProductWise]
@ItemCode int,
@year int,
@CustomerCode numeric(18,0),
@Month int,
@DataFrom nvarchar(15)
AS
Begin
select ItemCode, sum(ISNULL(Quantity,0)) as Quantity,
sum(ISNULL(GrossAmount,0)) as Amount
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
END
答案 1 :(得分:-1)
检查您在sp。
中传递的参数值