0

我正在尝试在 SP 下创建,但是当我尝试执行这所有五个参数时,它要求作为输入,最后 3 个是输出参数。有人可以指出我在搞砸什么以及如何解决它:

create PROCEDURE division_price_info_heatmap (@comp_id INT,
@compe_id INT, 
@Division_id INT out, 
@Division_name VARCHAR(20) out, 
@final_shipping_price DECIMAL(11,2) out)
AS
BEGIN
select T1.div, T1.div_n, (T1.price-T2.price)  as final_shipping_price from
(select  tcpi.division as div, td.division_name as div_n,
sum(tcpi.final_price_shipping) as price
from tb_competitor_product_info_new as tcpi 
inner join tb_division td on tcpi.division=td.division_id  
where competitor_id=@comp_id
group by tcpi.division, td.division_name
)   as T1,

(select  tcpi.division as div, td.division_name as div_n,
sum(tcpi.final_price_shipping) as price
from tb_competitor_product_info_new as tcpi 
inner join tb_division td on tcpi.division=td.division_id  
where competitor_id=@compe_id
group by tcpi.division, td.division_name
)   as T2
where T1.div=T2.div

END

执行命令:- division_price_info_heatmap 1,2

错误 :

错误:过程或函数“division_price_info_heatmap”需要参数“@Division_id”,但未提供该参数。SQLState:S0004 错误代码:201

我正在使用 mssql 和 squirrel UI。

还有一件事是我有必要分配参数。

4

2 回答 2

0

如果我没记错 MS SQL 不使用OUT关键字而是OUTPUT用于存储过程,请尝试更改该部分,它应该可以工作。请参阅此内容以供参考

当您调用该过程时,您必须提供将接收输出的变量,尽管就像在另一个答案中指出的那样。

在旁注中,看起来您实际上并未返回任何内容,因为您从未将任何内容分配给输出变量,但也许这存在于您遗漏的代码中。

此外,不需要围绕变量的括号,因此语句的开头应该是:

CREATE PROCEDURE division_price_info_heatmap 
  @comp_id INT,
  @compe_id INT, 
  @Division_id INT OUTPUT, 
  @Division_name VARCHAR(20) OUTPUT, 
  @final_shipping_price DECIMAL(11,2) OUTPUT
AS
于 2013-10-17T10:56:19.377 回答
0

您传递了两个参数,并且该过程需要更多参数。执行命令应该是:

DECLARE @Division_id INT, @Division_name VARCHAR(20), @final_shipping_price DECIMAL(11,2)
EXEC division_price_info_heatmap 1,2,@Division_id OUT,@Division_name OUT, @final_shipping_price OUT

或者您可以修改程序:

create PROCEDURE division_price_info_heatmap (@comp_id INT,
@compe_id INT, 
@Division_id INT = NULL out, 
@Division_name VARCHAR(20) = NULL out, 
@final_shipping_price DECIMAL(11,2) = NULL out)
AS
...
于 2013-10-17T10:59:30.563 回答