sql >> Base de Datos >  >> RDS >> Sqlserver

Reemplazar valor nulo por último valor

Esto funcionará para su caso, creo:

SELECT 
    t1.PositionDate,
    t1.Currency,
    COALESCE(t1.Value,t2.value) AS Value
FROM t1
LEFT join (SELECT MAX(PositionDate) AS PositionDate,Currency FROM t2 WHERE PositionDate < t1.PositionDate  GROUP BY Currency) tjoin
LEFT join t2 on tjoin.currency = t2.Currency and tjoin.PositionDate = t2.PositionDate