• I second Lynn regarding the needs to post DDL, sample data and expected result. Help us to be able to help you.

    Regarding the problem / question I find it easier to solve if we have one row per (Dept, ObjSub, FY, period). To get there you need to unpivot the periods, have a column of [date] type to do some date calculations and then pivot the data back.

    SET NOCOUNT ON;

    USE tempdb;

    GO

    DECLARE @T TABLE (

    FY smallint NOT NULL,

    ObjSub smallint NOT NULL,

    Dept smallint NOT NULL,

    P_01 int NOT NULL,

    P_02 int NOT NULL,

    P_03 int NOT NULL,

    P_04 int NOT NULL,

    P_05 int NOT NULL,

    P_06 int NOT NULL,

    P_07 int NOT NULL,

    P_08 int NOT NULL,

    P_09 int NOT NULL,

    P_10 int NOT NULL,

    P_11 int NOT NULL,

    P_12 int NOT NULL

    );

    INSERT INTO @T (

    FY,ObjSub, Dept, P_01, P_02, P_03, P_04, P_05, P_06, P_07, P_08, P_09, P_10, P_11, P_12)

    VALUES

    (13, 12345, 1, 12, 14, 78, 87, 85, 555, 5, 5, 5, 5, 5, 5),

    (14, 12345, 1, 555, 55, 5, 55, 555, 555, 88, 88, 9, 8, 1, 8),

    (13, 12349, 54, 55, 4545, 55, 5, 5, 5, 577, 7, 77, 77, 7777, 111),

    (14, 12349, 54, 555, 555, 51, 4, 6, 7444, 477, 788, 88, 221, 3654, 88);

    DECLARE

    @FY smallint = 14,

    @P smallint = 3;

    WITH C1 AS (

    SELECT

    CAST(CAST((((U.FY * 100) + STUFF(U.period, 1, 2, '')) * 100) + 1 AS char(8)) AS date) AS dt,

    U.ObjSub,

    U.Dept,

    val

    FROM

    @T

    UNPIVOT

    (

    val

    FOR period IN (P_01, P_02, P_03, P_04, P_05, P_06, P_07, P_08, P_09, P_10, P_11, P_12)

    ) AS U

    )

    , C2 AS (

    SELECT

    YEAR(dt) AS FY,

    'P_' + RIGHT('00' + LTRIM(MONTH(dt)), 2) AS period,

    ObjSub,

    Dept,

    val

    FROM

    C1

    WHERE

    dt BETWEEN DATEADD([month], -11, CAST(CAST((((@FY * 100) + @P) * 100) + 1 AS char(8)) AS date))

    AND CAST(CAST((((@FY * 100) + @P) * 100) + 1 AS char(8)) AS date)

    )

    SELECT

    *

    FROM

    C2

    PIVOT

    (

    MAX(val)

    FOR period IN (P_01, P_02, P_03, P_04, P_05, P_06, P_07, P_08, P_09, P_10, P_11, P_12)

    ) AS P

    ORDER BY

    Dept,

    ObjSub,

    FY;

    GO

    /*

    FYObjSubDeptP_01P_02P_03P_04P_05P_06P_07P_08P_09P_10P_11P_12

    2013123451NULLNULLNULL8785555555555

    2014123451555555NULLNULLNULLNULLNULLNULLNULLNULLNULL

    20131234954NULLNULLNULL555577777777777111

    2014123495455555551NULLNULLNULLNULLNULLNULLNULLNULLNULL

    */

    Since you are using SS 2012 or greater then you could use the function DATEFROMPARTS to convert the values (FY, Stuff(period, 1, 2, ''), 1) to a date.