I need to register two tables from an application, for this I must enter records to the first table tb_ ordered, to get your code, then I must capture that code to enter records to the table tb_detalle_pedido, according to the last code of tb_pedido generated .
When I execute the procedure, the following error occurs: 1241 - operand should contain 1 column.
This is my code:
delimiter $$
CREATE PROCEDURE sp_insert_pedidos(
var_cond_pago int,
var_referen varchar(90),
var_direcc_entrega varchar(100),
var_nombre_cli varchar(100),
var_fecha_entrega date,
var_cod_tipo_fact int,
var_cod_cli int,
var_cod_vend int,
-- detalle pedido
var_cod_prod int,
var_desc_prod varchar(100),
var_bonificacion varchar(50),
var_cantidad int,
var_precio double)
begin
-- actualizacion del pedido
declare var_cod_ped int;
declare var_total_ped double;
declare var_sub_total_ped double;
declare var_descuento double;
declare var_isc double;
declare var_igv double;
declare neto double;
insert into tb_pedidos(cond_pago, referen, direcc_entrega, nombre_cli, fecha_entrega, fecha_pedido, cod_tipo_fact, cod_cli, cod_vend)
values(var_cond_pago, var_referen, var_direcc_entrega, var_nombre_cli, var_fecha_entrega, curdate(), var_cod_tipo_fact, var_cod_cli, var_cod_vend);
set var_cod_ped =(SELECT cod_ped FROM tb_pedidos ORDER BY cod_ped DESC limit 1);
insert into tb_detalle_pedido (cod_ped, cod_prod, desc_prod, bonificacion, cantidad, precio, sub_total)
values(var_cod_ped, var_cod_prod, var_desc_prod, var_bonificacion, var_cantidad, var_precio,(cantidad * precio));
set var_total_ped = (SELECT sum(sub_total) AS total FROM tb_detalle_pedido where cod_ped=var_cod_ped);
set var_descuento = var_total_ped * 0.18;
set neto = var_total_ped * 0.18;
set var_igv = var_total_ped - neto;
set var_isc = var_total_ped * 0.18;
if(select * from tb_detalle_pedido where cod_ped = var_cod_ped) then
Update tb_pedidos
Set total_ped = var_total_ped and descuento = var_descuento, IGV = var_igv, isc = var_isc
where cod_ped = var_cod_ped;
end if;
end $$
delimiter ;
Thanks for your help.