cross tab query

  • hi all,

    how do i achieve this result

    division 2012 2013 2014 2015 2016

    xyz 1 0 0 0 10

    abcd 11 0 0 0 9

    lmn 3 0 0 0 5

    i have data for year 2012 and 2016 there is no data for 2013,2014,2015.

    please help me achieve this.

    any help is highly appreciated.

    regards

    fairozkhan

  • Hi there!

    You've given us your expected results, but we need some DDL and test data to show you how to get them.

    This article provides excellent guidelines: Forum Etiquette: How to post data/code on a forum to get the best help[/url]


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • data what i have

    division 2012 2013 2016

    xyz 1 0 10

    abcd 11 1 9

    lmn 9 4 11

    regards

  • imfairozkhan (1/15/2013)


    data what i have

    division 2012 2013 2016

    xyz 1 0 10

    abcd 11 1 9

    lmn 9 4 11

    regards

    I think I speak from experience when I say that people here really want to help you. However we're all volunteers. So to get good, tested code you really need to follow the guidelines that are in the article link that I posted. You have not, which leads me to believe you didn't read it.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

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

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