update vs4tinventoryLOT set timcUnitratio=(select top 1 TInmUnitRatio from vs4tinventoryMB where 
vs4tinventoryMB.tinmtpdtcode=vs4tinventoryLOT.timctpdtcode and vs4tinventoryMB.tinmlotno=vs4tinventoryLOT.timclotno
and vs4tinventoryMB.tinmcustom1=vs4tinventoryLOT.timccustom1
and vs4tinventoryMB.tinmlotdate=vs4tinventoryLOT.timclotdate and vs4tinventoryMB.tinmserialno=vs4tinventoryLOT.timcserialno
and TInMAmouQuantity>0
and (tinmtintalias in ('LOTIN','LOTINPOP','LOTINPR','LOTINPREMIUM','RECEIVEFGBUILT','RECEIVEFGBUILTOUT','RECEIVEFGBUILTNOMRP')
or (tinmtintalias in ('BEGINBALANCE') and tinmsourceType<>9))
)
GO
update vs4tinventorylot set TIMCUnitRatio=1 where TIMCUnitRatio=0 or TIMCUnitRatio is null
GO
