update vs4tarinvoice set tivobaseincotype='EXW'  
where tivotype=6 and (tivobaseincotype='' or tivobaseincotype is null)
GO

update vs4tarinvoice set tivotaxbase = (tivosubtotal+TIvoOtherFee+TIvoHandlingFee)*tivoexchangerate
where tivotype=6 and tivobaseincotype='EXW'
GO

update vs4tarinvoice set tivotaxbase = (tivosubtotal)*tivoexchangerate
where tivotype=6 and tivobaseincotype='FOB'
GO

update vs4tarinvoicemb set tiomflag2=(select tivotype from vs4tarinvoice where 
vs4tarinvoicemb.tiomtivono = vs4tarinvoice.tivono)
GO

update vs4tarinvoice set tivoflag3=0
GO
update vs4tarinvoice set tivoflag3=3 where tivobaseincotype='EXW'
GO
update vs4tarinvoicemb set tiomflag3=(select tivoflag3 from vs4tarinvoice where vs4tarinvoicemb.tiomtivono = vs4tarinvoice.tivono)
GO

update vs4tarinvoicemb set tiomtaxbase = (select tivotaxbase*(tiomnetamount/tivosubtotal) from vs4tarinvoice Where
vs4tarinvoicemb.tiomtivono = vs4tarinvoice.tivono and tivosubtotal<>0)
where tiomflag2=6 and tiomflag3=3
GO
