Pivot

  • Hi guys,

    I have table with sample data below.

    I want to retrieve the record for the fiscal year FY-12 i.e Between 01-10-2012 to 30-09-2013..One year data

    WorkId ChildName PlanStartDate PlanEndDate

    158 Improve trucks NULL 2012-12-21

    158 Define NULL 2011-12-31

    158 Measure 2011-12-31 2012-01-07

    158 Analyze 2012-01-07 2012-02-11

    158 Improve 2012-02-11 2012-09-29

    I want the result to be like below

    WorkId ChildName Oct Nov Dec Jan feb March.........Sep

    158 Improve trucks NULL NULL Define Measure Analyze Analyze Analyze

    Comparing with plan start and end date i need to pivot the data for fiscal year...

  • With no more details than that I will suggest you to look at the article in my signature about cross tabs. It will explain how to accomplish this.

    If you need help with the code you should read the article in my signature about best practices when posting questions.

    _______________________________________________________________

    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/

  • farooq.hbs (2/1/2013)


    Hi guys,

    I have table with sample data below.

    I want to retrieve the record for the fiscal year FY-12 i.e Between 01-10-2012 to 30-09-2013..One year data

    WorkId ChildName PlanStartDate PlanEndDate

    158 Improve trucks NULL 2012-12-21

    158 Define NULL 2011-12-31

    158 Measure 2011-12-31 2012-01-07

    158 Analyze 2012-01-07 2012-02-11

    158 Improve 2012-02-11 2012-09-29

    I want the result to be like below

    WorkId ChildName Oct Nov Dec Jan feb March.........Sep

    158 Improve trucks NULL NULL Define Measure Analyze Analyze Analyze

    Comparing with plan start and end date i need to pivot the data for fiscal year...

    So what happened to "Improve"???

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply