UPDATE VS4TInventory set TInvInvoiceStatus=1,
TInvRefNo3=(SELECT DISTINCT TOP 1 TIPMTIAPNo FROM VS4TAPInvoiceMB where TIPMGRNNo=VS4TInventory.TInvNo)
WHERE TInvRefNo3='' or TInvRefNo3 is null and TInvInvoiceStatus=0 AND TInvTInTAlias LIKE 'LOTIN%'
and ((SELECT SUM(TInMInQuantity) AS Q FROM VS4TInventoryMB WHERE TInMTInvNo=VS4TInventory.TInvNo)=
(SELECT SUM(TIPMUnitFactor*TIPMQuantityCalc) AS QB FROM VS4TAPInvoiceMB where TIPMGRNNo=VS4TInventory.TInvNo)
AND (SELECT SUM(TInMInQuantity) AS Q FROM VS4TInventoryMB WHERE TInMTInvNo=VS4TInventory.TInvNo)>0)
GO

UPDATE VS4Tinventory SET TInvInvoiceStatus=0 WHERE (TInvRefNo3='' or TInvRefNo3 is null) AND TInvTInTAlias LIKE 'LOTIN%'
GO






