Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

Consulta para obter a junção mais recente em outra tabela com data

SELECT  *
FROM    #EventOccurrence eo
OUTER APPLY
        (
        SELECT  TOP 1 Grade
        FROM    #GradeChange gc
        WHERE   gc.id = eo.id
                AND gc.EffectiveDate <= eo.EventDate
        ORDER BY
                gc.EffectiveDate DESC
        ) gc