Hi, I want to make a trigger that when the stock of my inventory is less than or equal to 0, it does not allow me to sell more product but it still subtracts them anyway.
create trigger NoProductos0a on InventarioProducto for update
as
declare @cantidad int
select @cantidad = count(InventarioProducto.Cantidad) from InventarioProducto
if (@cantidad<0)
begin
print 'No se puede realizar la venta, supera la cantidad existente del producto.'
end
The structure of the table is as follows
InventarioProducto
IdProducto int identity(1,1)
Nom_Producto varchar(50)
Precio_Uni decimal(18,2)
Cantidad int
The value of Quantity is 5 and I try that when executing this command I do not get results -1
update InventarioProducto set Cantidad-=6 where IdProducto=1