Home Forums SQL Server 2008 T-SQL (SS2K8) How to Calculate a column value, based on previous column value RE: How to Calculate a column value, based on previous column value

  • Ahh gotcha. Don't understand the usefulness of something like this but this is how you would do the query.

    select ActNo, max(case when ProcessMonth = '2012-Jul' then PlanName else '' end) as JulyResult

    , MAX(case when ProcessMonth = '2012-Oct' then PlanName else '' end) as OctResult

    , case when max(case when ProcessMonth = '2012-Jul' then PlanName else '' end) = MAX(case when ProcessMonth = '2012-Oct' then PlanName else '' end) then 2 else 1 end

    from #tempo1

    group by ActNo

    order by ActNo

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/