Beruflich Dokumente
Kultur Dokumente
begin
declare exist int;
declare idprod int;
if cantidad<0 then
select 'La cantidad a vender no puede ser negativa' as mensaje;
end if;
if cantidad=0 then
select 'Imposible no vender ningun producto' as mensaje1;
end if;
select p_existencia into exist from producto where p_nombre=nombre;
select p_id_producto into idprod from producto where p_nombre=nombre;
if cantidad>exist then
select 'La cantidad excede la existencia de productos' as mensaje2;
end if;
if exist=0 then
select 'El producto se ha terminado' as mensaje3;
end if;
if cantidad>0 then
if cantidad<=exist then
insert into vender values (idprod,nota,cantidad);
update producto set p_existencia=exist-cantidad where p_nombre=nombre;
select n_id_nota as 'Nota',p_nombre as 'Nombre Producto', v_cantidad as
'Cantidad' ,p_precio_unitario as 'Precio Unitario',
(v_cantidad*p_precio_unitario) as 'subtotal'
from producto, vender, nota
where p_id_producto=v_id_producto & n_id_nota=v_id_nota & n_id_nota=nota;
select sum (v_cantidad * p_precio_unitario) as 'Total de Venta'
from producto, vender, nota
where p_id_producto=v_id_producto and
n_id_nota=v_id_nota and
n_id_nota=nota;
select 'El producto ha sido vendido' as mensaje4;
end if;
end if;
end
EJECUTAR EL PROCEDIMIENTO ALMACENADO realizarVenta
call realizarVenta (1,-3,'Cafe') es la manera de ejecutar un procedimiento
almacenado pero al no devolverme ningn valor, las pruebas las hice graficas:
Regla 4:
Productos existentes antes de realizar una venta