UPDATE VS4TAPInvoice SET TIAPWTaxTotal=(SELECT isnull(SUM(TTxTWTaxAmount),0) FROM VS4TTaxTrans WHERE TTxTTTaxAlias='WTAX' AND VS4TTaxTrans.TTxTDocNo=VS4TAPInvoice.TIAPNo)
WHERE (TIAPType in (1,9)) and TIAPWTaxTotal=0
GO