Update VS4TInventoryLOT Set TIMCReceiveNo=(SELECT Top 1 TInMTInvNo FROM VS4TInventoryMB
WHERE VS4TInventoryMB.TinmTPdtcode=VS4TInventoryLOT.TIMCTPdtCode 
AND VS4TInventoryMB.TinmCustom1=VS4TInventoryLOT.TIMCCustom1 
AND VS4TInventoryMB.TinmLotno=VS4TInventoryLOT.TIMCLotNo 
AND VS4TInventoryMB.TinmLotdate=VS4TInventoryLOT.TIMCLotdate 
AND VS4TInventoryMB.TinmSerialNo=VS4TInventoryLOT.TIMCSerialNo 
AND TInMAmouQuantity>0
AND (TInMTInTAlias like 'LOTIN%' or TInMTInTAlias like 'RECEIVEFG%' or TInMTInTAlias like 'BEGINBALANCE%')
ORDER BY TInMFlag3 DESC
) 
WHERE TIMCReceiveNo='' or TIMCReceiveNo is Null
GO

Update VS4TInventoryLOT Set TIMCReceiveLn=(SELECT Top 1 TInMLn FROM VS4TInventoryMB
WHERE VS4TInventoryMB.TinmTPdtcode=VS4TInventoryLOT.TIMCTPdtCode 
AND VS4TInventoryMB.TinmCustom1=VS4TInventoryLOT.TIMCCustom1 
AND VS4TInventoryMB.TinmLotno=VS4TInventoryLOT.TIMCLotNo 
AND VS4TInventoryMB.TinmLotdate=VS4TInventoryLOT.TIMCLotdate 
AND VS4TInventoryMB.TinmSerialNo=VS4TInventoryLOT.TIMCSerialNo 
AND TInMAmouQuantity>0
AND (TInMTInTAlias like 'LOTIN%' or TInMTInTAlias like 'RECEIVEFG%' or TInMTInTAlias like 'BEGINBALANCE%')
ORDER BY TInMFlag3 DESC
) 
WHERE TIMCReceiveLn=0
GO
