UPDATE VS4TAPVoucher Set TAPVBaseArrear=(SELECT SUM(TPVRRefDocAmount) FROM VS4TAPVDocRef where VS4TAPVDocRef.TPVRTAPVNo=VS4TAPVoucher.TAPVNo) WHERE   TAPVType<3
GO
UPDATE VS4TAPVoucher Set TAPVCurDiscount=round(TAPVArrear*((SELECT SUM(TPVRTaxBase) FROM VS4TAPVDocRef where VS4TAPVDocRef.TPVRTAPVNo=VS4TAPVoucher.TAPVNo)/TAPVBaseArrear),2) WHERE TAPVBaseArrear<>0 AND TAPVBaseArrear is not null AND TAPVType<3
GO
