• Since the table already contains the previous year's YTD totals, would a simple LEFT JOIN suffice to get the prior year's YTD total?

    SELECT

    t1curr.cod, t1curr.[year], t1curr.[month], t1curr.value, t1prev.value

    FROM dbo.Table_1 t1curr

    LEFT OUTER JOIN dbo.Table_1 t1prev ON

    t1prev.cod = t1curr.cod AND

    t1prev.[year] = t1curr.[year] - 1 AND

    t1prev.[month] = t1curr.[month]

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.