I am trying to do a procedure stored in SQL for a restaurant sales system that when adding a dish to a sale check if there is stock of the ingredients available and return a response 1 if there is or 0 if there is not.
ALTER proc [dbo].[check_stock_venta]
@Idplato int,
@Cantidad int,
@Rpta int output
as
i.Stock;t.Cantidad from Insumos i join (select
dp.id_insumo,Cantidad=sum(dp.Cantidad*@Cantidad) from Detalles_plato dp
where dp.id_plato=@Idplato group by dp.id_insumo)t on i.Idinsumo=t.id_insumo
At the moment I have done a join of the tables to have the fields I need, I had thought about using an if with the fields
-
i.Stock
-
t.Cantidad
and if this if returned the answer if the stock was greater than or equal to the amount, I do not know if it is the best way to do this and on the other hand I do not know how to use these two fields after doing the join of the tables .
I leave a link where you can see how tables are made and related .