• Try below..Modify it as per your need.

    ;WITH Abstraction(pYear, pMonth, pValue, jan,feb,mar,april,may,june,july,aug,sep,oct,nov,decb) AS

    (

    SELECT 1999

    ,12

    ,cast (0 as float)

    ,cast (0 as float)

    ,cast (null as float)

    ,cast (null as float)

    ,cast (null as float)

    ,cast (null as float)

    ,cast (null as float)

    ,cast (null as float)

    ,cast (null as float)

    ,cast (null as float)

    ,cast (null as float)

    ,cast (null as float)

    ,cast (null as float)

    UNION ALL

    SELECT CASE WHEN pMonth = 12 THEN pYear + 1 ELSE pYear END

    ,CASE WHEN pMonth = 12 THEN 1 ELSE pMonth + 1 END

    ,pv.pvalue

    ,case when pmonth = 12 then isnull(jan,0.0) + pv.pvalue else ISNULL(jan,0.0) end as jan --this value is for jan if the pmonth is 12 and simialrly below

    ,case when pmonth = 1 then isnull(feb,0.0) + pv.pvalue else isnull(feb,0.0) end as feb

    ,case when pmonth = 2 then isnull(mar,0.0) + pv.pvalue else isnull(mar,0.0) end as mar

    ,case when pmonth = 3 then isnull(april,0.0) + pv.pvalue else isnull(april,0.0) end as april

    ,case when pmonth = 4 then isnull(may,0.0) + pv.pvalue else isnull(may,0.0) end as may

    ,case when pmonth = 5 then isnull(june,0.0) + pv.pvalue else isnull(june,0.0) end as june

    ,case when pmonth = 6 then isnull(july,0.0) + pv.pvalue else isnull(july,0.0) end as july

    ,case when pmonth = 7 then isnull(aug,0.0) + pv.pvalue else isnull(aug,0.0) end as aug

    ,case when pmonth = 8 then isnull(sep,0.0) + pv.pvalue else isnull(sep,0.0) end as sep

    ,case when pmonth = 9 then isnull(oct,0.0) + pv.pvalue else isnull(oct,0.0) end as oct

    ,case when pmonth = 10 then isnull(nov,0.0) + pv.pvalue else isnull(nov,0.0) end as nov

    ,case when pmonth = 11 then isnull(decb,0.0) + pv.pvalue else isnull(decb,0.0) end as decb

    FROM Abstraction a

    cross apply(select cast (RAND(CAST(CAST(NEWID()AS VARBINARY) AS int)) * 1000 as float) pvalue) pv

    WHERE CASE WHEN pMonth = 12 THEN pYear + 1 ELSE pYear END <= 2005

    )

    SELECT

    pYear,pMonth,pValue,

    case

    when pmonth = 1 then jan

    when pmonth = 2 then feb

    when pmonth = 3 then mar

    when pmonth = 4 then april

    when pmonth = 5 then may

    when pmonth = 6 then june

    when pmonth = 7 then july

    when pmonth = 8 then aug

    when pmonth = 9 then sep

    when pmonth = 10 then oct

    when pmonth = 11 then nov

    when pmonth = 12 then decb

    end as problem

    FROM Abstraction

    where pYear>= 2000

    GulliMeel

    Finding top n Worst Performing queries[/url]
    Improve the performance of Merge Join(special case)
    How to Post Performance Problem -Gail Shaw[/url]