UPDATE VS4TAPVDocRef Set TPVRFlag2=0
GO
UPDATE VS4TAPVDocRef Set TPVRFlag2=(SELECT 99 FROM VS4TARInvoice WHERE VS4TARInvoice.TIvoNo=VS4TAPVDocRef.TPVRTAPVNO AND VS4TARInvoice.TIvoType in(1,5,7))
GO
UPDATE VS4TAPVDocRef Set TPVRRefDocAmount=(SELECT TIvoGrandTotal FROM VS4TARInvoice WHERE VS4TARInvoice.TIvoNo=VS4TAPVDocRef.TPVRTAPVNO AND VS4TARInvoice.TIvoType in(1,5,7)) WHERE TPVRFlag2=99
GO
UPDATE VS4TAPVDocRef Set TPVRAmountRate=TPVRRefDocAmount,TPVRCurAmount=TPVRRefDocAmount  WHERE TPVRFlag2=99
GO
UPDATE VS4TAPVDocRef Set TPVRTaxBase=(SELECT TIvoTaxBase FROM VS4TARInvoice WHERE VS4TARInvoice.TIvoNo=VS4TAPVDocRef.TPVRTAPVNO AND VS4TARInvoice.TIvoType in(1,5,7)) WHERE TPVRFlag2=99
GO