Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

cross tab query Expand / Collapse
Author
Message
Posted Tuesday, January 15, 2013 1:01 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, August 28, 2013 2:45 AM
Points: 19, Visits: 46
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
Post #1407061
Posted Tuesday, January 15, 2013 1:34 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 6:20 AM
Points: 3,627, Visits: 5,269
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



My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

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?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
Post #1407076
Posted Tuesday, January 15, 2013 2:03 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, August 28, 2013 2:45 AM
Points: 19, Visits: 46
data what i have
division 2012 2013 2016
xyz 1 0 10
abcd 11 1 9
lmn 9 4 11

regards
Post #1407092
Posted Tuesday, January 15, 2013 2:08 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 6:20 AM
Points: 3,627, Visits: 5,269
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!

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?
Since random numbers are too important to be left to chance, let's generate some!
Learn to understand recursive CTEs by example.
Splitting strings based on patterns can be fast!
Post #1407094
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse