USE POWERPOS GO /****** Object: StoredProcedure [dbo].[sp_update_stock_inventory_carcass] Script Date: 01/22/2026 8:55:38 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO DROP PROCEDURE sp_update_stock_inventory_carcass GO CREATE PROCEDURE [dbo].[sp_update_stock_inventory_carcass] as BEGIN SET NOCOUNT ON; --reset balances update delivery set qty_in =0,qty_out=0,end_qty=0 update delivery set qty_out = (select isnull(sum(a.qty),0) from cuts_history a where a.parent_code= delivery.itemcode and a.source_batch = delivery.ref_no) --from delivery, cuts_history --where delivery.itemcode = cuts_history.parent_code --and delivery.ref_no = cuts_history.parent_batch update delivery set end_qty = isnull(qty,0) - isnull(qty_out,0) END GO