Buen día, estoy intentando crear una TN para obligar que respeten el almacén de la Orden de Compra al momento de crear una Factura, tengo lo siguiente:
if @object_type='18' and @transaction_type in ('A')
begin
declare
@Inv numeric(19,6)
,@Pur numeric(19,6)
set @Inv=isnull((select distinct SUM(CONVERT(NUMERIC(18,2),T0.[WhsCode])) from PCH1 T0 where T0.BaseType='22' and
T0.BaseEntry in (select distinct A.BaseEntry from POR1 A where A.DocEntry=@list_of_cols_val_tab_del and A.BaseType='22' AND T0.ItemCode=A.ItemCode)),0)
set @Pur=isnull((select distinct SUM(CONVERT(NUMERIC(18,2),T0.[WhsCode])) from POR1 T0 where T0.DocEntry in
(select distinct A.BaseEntry from PCH1 A where A.DocEntry=@list_of_cols_val_tab_del and A.BaseType='22' and T0.ItemCode=A.ItemCode)),0)
if (@Pur-@Inv)<> 0
begin
set @error='123'
set @error_message ='El almacén no puede ser diferente al de la OC'
end
end
Funciona siempre y cuando no elimine ninguna línea…