Handy Manny
Handy Manny

Reputation: 388

Multiply two columns and put result in third column during insertion in mysql using stored procedure

I want to do something like this:

Quantity   Price    Payment
1           12      12.00

Here's my code:

CREATE DEFINER=`root`@`localhost` 
PROCEDURE `insertproducts`
(
    pname varchar(50), 
    pdesc varchar(50),
    psupp varchar(50),
    pdate date,
    pquant int,
    pprice double
)
begin
insert into products
(
    prodname,
    proddescription,
    prodsupplier,
    proddate,
    prodquantity,
    prodprice,
    prodpayment
) 
values 
(
    pname,
    pdesc,
    psupp,
    pdate,
    pquant,
    pprice,
    ppayment
) 
set prodpayment = pprice * prodquantity;
end

This is not working, any idea?

Upvotes: 2

Views: 1515

Answers (1)

John Woo
John Woo

Reputation: 263803

what is ppayment? You can directly multiply the parameters,

insert into products
(
    prodname, 
    proddescription, 
    prodsupplier, 
    proddate, 
    prodquantity, 
    prodprice, 
    prodpayment
) 
values 
(
    pname, 
    pdesc, 
    psupp, 
    pdate, 
    pquant, 
    pprice, 
    pprice*prodquantity
)

Upvotes: 3

Related Questions