UPDATE VS4TARVDocRef Set TRDRFlag2=0
GO
UPDATE VS4TARVDocRef Set TRDRFlag2=(SELECT 99 FROM VS4TARInvoice WHERE VS4TARInvoice.TIvoNo=VS4TARVDocRef.TRDRTRVHNO AND VS4TARInvoice.TIvoType in(1,5,7))
GO
UPDATE VS4TARVDocRef Set TRDRRefDocAmount=(SELECT TIvoGrandTotal FROM VS4TARInvoice WHERE VS4TARInvoice.TIvoNo=VS4TARVDocRef.TRDRTRVHNO AND VS4TARInvoice.TIvoType in(1,5,7)) WHERE TRDRFlag2=99
GO
UPDATE VS4TARVDocRef Set TRDRAmountRate=TRDRRefDocAmount,TRDRCurAmount=TRDRRefDocAmount  WHERE TRDRFlag2=99
GO
UPDATE VS4TARVDocRef Set TRDRTaxBase=(SELECT TIvoTaxBase FROM VS4TARInvoice WHERE VS4TARInvoice.TIvoNo=VS4TARVDocRef.TRDRTRVHNO AND VS4TARInvoice.TIvoType in(1,5,7)) WHERE TRDRFlag2=99
GO