• 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) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".