UPDATE VS4TARVoucher Set TRVHBaseArrear=(SELECT SUM(TRDRRefDocAmount) FROM VS4TARVDocRef where VS4TARVDocRef.TRDRTRVHNo=VS4TARVoucher.TRVHNo) WHERE   TRVHType<3
GO
UPDATE VS4TARVoucher Set TRVHCurDiscount=round(TRVHArrear*((SELECT SUM(TRDRTaxBase) FROM VS4TARVDocRef where VS4TARVDocRef.TRDRTRVHNo=VS4TARVoucher.TRVHNo)/TRVHBaseArrear),2) WHERE TRVHBaseArrear<>0 AND TRVHBaseArrear is not null AND TRVHType<3
GO
