update vs4tproduct set tpdtaveragecost=0  where tpdtaveragecost is null
update vs4tproduct set tpdtaveragecost=(select timunitcost from vs4vtstock  where vs4tproduct.tpdtcode=vs4vstock.tpdtcode
update vs4tproduct set tpdtaveragecost=0  where tpdtaveragecost is null
update vs4tproduct set tpdtaveragecost=tpdtlastcost  where tpdtaveragecost=0 and tpdtlastcost>0
update vs4tproduct set tpdtlastcost =tpdtaveragecost  where tpdtlastcost  is null or tpdtlastcost  = 0
update VS4TInvoiceMB set TIoMcost=(select tpdtaveragecost from vs4tproduct
where tpdtcode=TIoMtposcode)
update VS4TInvoiceMB set TIoMcost=0 where TIoMcost is null
update VS4TInvoiceMB set TIoMcostamount=TIoMcost*TIoMquantity
update VS4TInvoice set TIvocosttotal=(select sum(TIoMcostamount) from VS4TInvoicemb
where TIoMTIvono=TIvono)