user3930037
user3930037

Reputation: 27

To add numbers and Divide it in Stored Procedure

In the below code I have to add 4 values and divide by another value. It throws error

must declare scalar variable

Please help me to solve the issue.

// 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

Upvotes: 0

Views: 1204

Answers (2)

SchmitzIT
SchmitzIT

Reputation: 9572

Replace this:

// 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

with this:

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

You'll have to reassign new names to the incoming parameters, though, as you cannot reuse the same names twice.

Upvotes: 0

Sanket Tarun Shah
Sanket Tarun Shah

Reputation: 637

You are re-declaring the same variables inside the stored procedure and they will remain uninitialized causing the error you are getting.

Upvotes: 1

Related Questions