UPDATE VS4TInventoryLOT SET TIMCTInTAlias=(SELECT TOP 1  TINMTINTAlias FROM VS4TinventoryMB 
 WHERE VS4TinventoryLOT.TIMCTPdtCode=VS4TinventoryMB.TInMTPdtCode
 AND VS4TinventoryLOT.TIMCLotNo =VS4TinventoryMB.TInMLotNo 
 AND VS4TinventoryLOT.TIMCLotDate=VS4TinventoryMB.TInMLotDate 
 AND VS4TinventoryLOT.TIMCCustom1 =VS4TinventoryMB.TInMCustom1 
 AND VS4TinventoryLOT.TIMCSerialNo =VS4TinventoryMB.TInMSerialNo
 AND VS4TinventoryMB.TInMAmouQuantity>0
 AND VS4TinventoryMB.TInMTInTAlias in ('LOTIN','LOTINPOP','LOTINPR','RECEIVEBUILT','RECEIVEBUILTOUT','REPACK','ADJUST','BEGINBALANCE')
 )
 WHERE TIMCTInTAlias='' or TIMCTInTAlias is null
GO

UPDATE VS4TInventoryLOT SET TIMCcostinputtype=1 where TIMCTInTAlias='REPACK'
GO

UPDATE VS4TInventoryLOT SET TIMCUnitRatioC=(SELECT isnull(SUM(TINMAmouQuantity),0) FROM VS4TinventoryMB 
 WHERE VS4TinventoryLOT.TIMCReceiveNo =VS4TinventoryMB.TInMTInvNo 
 AND VS4TinventoryMB.TInMAmouQuantity>0
 AND VS4TinventoryMB.TInMTInTAlias in ('LOTIN','LOTINPOP','LOTINPR','RECEIVEBUILT','RECEIVEBUILTOUT','REPACK','ADJUST','BEGINBALANCE')
)
WHERE TIMCCostInputType=1 AND TIMCTInTAlias='REPACK'
GO

UPDATE VS4TInventoryLOT set TIMCUnitRatioC=1 WHERE TIMCCostInputType = 1 And (TIMCUnitRatioC = 0 Or TIMCUnitRatioC Is Null)
GO