UPDATE VS4TTaxTrans Set TTxtTBraCode=(SELECT TIvoTBraCode FROM VS4TARInvoice WHERE VS4TARInvoice.TIvoNO=VS4TTaxTrans.TTxTDocNo)
WHERE (TTxtTBraCode='' or TTxtTBraCode is null) and TTxTSaveFrom='IV'
GO
UPDATE VS4TTaxTrans Set TTxtTBraCode=(SELECT TRCNTBraCode FROM VS4TARCreditNote WHERE VS4TARCreditNote.TRCNNO=VS4TTaxTrans.TTxTDocNo)
WHERE (TTxtTBraCode='' or TTxtTBraCode is null) and TTxTSaveFrom='CN'
GO
UPDATE VS4TTaxTrans Set TTxtTBraCode=(SELECT TDBNTBraCode FROM VS4TARDebitNote WHERE VS4TARDebitNote.TDBNNO=VS4TTaxTrans.TTxTDocNo)
WHERE (TTxtTBraCode='' or TTxtTBraCode is null) and TTxTSaveFrom='DB'
GO
UPDATE VS4TTaxTrans Set TTxtTBraCode=(SELECT TRVHTBraCode FROM VS4TARVoucher WHERE VS4TARVoucher.TRVHNO=VS4TTaxTrans.TTxTDocNo)
WHERE (TTxtTBraCode='' or TTxtTBraCode is null) and TTxTSaveFrom='RV'
GO
UPDATE VS4TTaxTrans Set TTxtTBraCode=(SELECT TIAPTBraCode FROM VS4TAPInvoice WHERE VS4TAPInvoice.TIAPNO=VS4TTaxTrans.TTxTDocNo)
WHERE (TTxtTBraCode='' or TTxtTBraCode is null) and TTxTSaveFrom='PIV'
GO
UPDATE VS4TTaxTrans Set TTxtTBraCode=(SELECT TPCNTBraCode FROM VS4TAPCreditNote WHERE VS4TAPCreditNote.TPCNNO=VS4TTaxTrans.TTxTDocNo)
WHERE (TTxtTBraCode='' or TTxtTBraCode is null) and TTxTSaveFrom='PCN'
GO
UPDATE VS4TTaxTrans Set TTxtTBraCode=(SELECT TDENTBraCode FROM VS4TAPDebitNote WHERE VS4TAPDebitNote.TDENNO=VS4TTaxTrans.TTxTDocNo)
WHERE (TTxtTBraCode='' or TTxtTBraCode is null) and TTxTSaveFrom='PDB'
GO
UPDATE VS4TTaxTrans Set TTxtTBraCode=(SELECT TAPVTBraCode FROM VS4TAPVoucher WHERE VS4TAPVoucher.TAPVNO=VS4TTaxTrans.TTxTDocNo)
WHERE (TTxtTBraCode='' or TTxtTBraCode is null) and TTxTSaveFrom='PV'
GO
UPDATE VS4TTaxTrans Set TTxtTBraCode=(SELECT TAPVTBraCode FROM VS4TAPVoucher WHERE VS4TAPVoucher.TAPVNO=VS4TTaxTrans.TTxTDocNo)
WHERE (TTxtTBraCode='' or TTxtTBraCode is null) and TTxTSaveFrom='PC'
GO
UPDATE VS4TTaxTrans Set TTxtTBraCode=(SELECT TEmpTBraCode FROM VS4TEmployee WHERE VS4TEmployee.TEmpCode=VS4TTaxTrans.TTxTClientCode)
WHERE (TTxtTBraCode='' or TTxtTBraCode is null) and TTxTSaveFrom='SL'
GO
UPDATE VS4TTaxTrans Set TTxtTBraCode=(SELECT TGLTTBraCode FROM VS4TGLTrans WHERE VS4TGLTrans.TGLTNO=VS4TTaxTrans.TTxTTGLTNo)
WHERE (TTxtTBraCode='' or TTxtTBraCode is null)
GO
UPDATE VS4TTaxTrans Set TTxtTBraCode=(SELECT TBraCode FROM VS4TBranch WHERE TBraTBrTAlias='HEADOFFICE')
WHERE (TTxtTBraCode='' or TTxtTBraCode is null)
GO
