• use below code:

    CREATE TABLE #Table(

    [cod] [nchar](10) NULL,

    [year] [int] NULL,

    [month] [tinyint] NULL,

    [value] [float] NULL

    ) ON [PRIMARY]

    GO

    insert into #Table values ('cod1',2011,1,100)

    insert into #Table values ('cod1',2011,2,150)

    insert into #Table values ('cod1',2011,3,200)

    insert into #Table values ('cod1',2012,1,100)

    insert into #Table values ('cod1',2012,2,180)

    select cod,year,month,sum(value) val

    into #temp1 from

    (select * from #Table t2

    UNION

    select t2.cod,T2.year+1,t2.month,'' ppy from #Table t2

    WHERE T2.month not in(select isnull(t5.month,0) as month from #Table t5 where (T2.year-1)=T5.year)

    )k

    group by cod,year,month

    select cod,year,month,CASE WHEN val<>0 THEN val END val,(select SUM(t1.val) from #temp1 t1 WHERE (T2.year-1)=T1.year AND T2.month>=T1.month) AS PPY from #temp1 T2