• Hi Jack

    Please check this out:

    WITH rt (rn, date,contact,ammout) AS

    (SELECT ROW_NUMBER() OVER (PARTITION BY s1.contact ORDER BY s2.date) AS rn ,s2.date,s1.contact,s1.amount from tb2 AS s2 LEFT OUTER JOIN tb1 AS s1 ON s2.date >= s1.date)

    SELECT rt.date,rt.contact,rt.ammout FROM rt INNER JOIN

    (SELECT date,contact,max(rn) as rn FROM rt

    GROUP BY contact,date) as t ON rt.rn =t.rn AND rt.date = t.date and rt.contact = t.contact

    ORDER BY rt.contact,rt.date;

    Best regards

    Mike