Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 在存储过程中添加数字并将其除_Sql_Sql Server_Stored Procedures - Fatal编程技术网

Sql 在存储过程中添加数字并将其除

Sql 在存储过程中添加数字并将其除,sql,sql-server,stored-procedures,Sql,Sql Server,Stored Procedures,在下面的代码中,我必须添加4个值并除以另一个值。它抛出错误 必须声明标量变量 请帮我解决这个问题 // Passing the values @i_TransferQuantity float, @i_OnetimeCharge float, @i_LoadingCharge float, @i_UnLoadingCharge float, @i_FreightCharge float, @i_UnitPrice float DECLARE @i_Loa

在下面的代码中,我必须添加4个值并除以另一个值。它抛出错误

必须声明标量变量

请帮我解决这个问题

// Passing the values
@i_TransferQuantity float,
    @i_OnetimeCharge float,
    @i_LoadingCharge float,
    @i_UnLoadingCharge float,
    @i_FreightCharge float,
    @i_UnitPrice float

DECLARE @i_LoadingCharge, @i_UnLoadingCharge,
        @i_FreightCharge, @i_UnitPrice,
        @i_TotalUnitPrice, @i_TransferQuantity Float

SET @i_TotalUnitPrice = @i_LoadingCharge + @i_UnLoadingCharge +
                        @i_FreightCharge + @i_UnitPrice / @i_TransferQuantity

您正在存储过程中重新声明相同的变量,这些变量将保持未初始化状态,从而导致出现错误。

替换此变量:

// Passing the values
@i_TransferQuantity float,
    @i_OnetimeCharge float,
    @i_LoadingCharge float,
    @i_UnLoadingCharge float,
    @i_FreightCharge float,
    @i_UnitPrice float

DECLARE @i_LoadingCharge, @i_UnLoadingCharge,
        @i_FreightCharge, @i_UnitPrice,
        @i_TotalUnitPrice, @i_TransferQuantity Float
为此:

DECLARE @i_LoadingCharge float, @i_UnLoadingCharge float,
        @i_FreightCharge float, @i_UnitPrice float,
        @i_TotalUnitPrice float, @i_TransferQuantity float
但是,您必须为传入参数重新分配新名称,因为您不能重复使用相同的名称两次。

是否确实要仅将
@i_UnitPrice
除以
@i_TransferQuantity
?或者,您想将这四个变量相加,然后将它们的和除以
@i_TransferQuantity
?在这种情况下,您缺少一些括号!