Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
davidliv
Starting Member
45 Posts |
Posted - 2004-05-16 : 22:28:46
|
| Okay, here is my table formattable structureitem_id intitemtype_iditem_qtr datetimeitem_cost intData ExampleID..Type...Qtr.......Cost1....1.....1/1/2003...552....1.....4/1/2003...453....1.....7/1/2003...504....1.....10/1/2003..405....1.....1/1/2004...506....1.....4/1/2004...257....1.....7/1/2004...108....1.....10/1/2004..309....2.....1/1/2003...5510...2.....4/1/2003...4511....2.....7/1/2003...5012....2.....10/1/2003..4013....2.....1/1/2004...5014....2.....4/1/2004...2515....2.....7/1/2004...1016....2.....10/1/2004..30Here is what I want my results to look like, but I can't figure out the grouping.................2003............2004.....Item Type...Q1..Q2..Q3..Q4..Q1..Q2..Q3..Q41...........55..45..50..40..50..25..10..302...........55..45..50..40..50..25..10..30 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-05-16 : 22:46:37
|
| Search for pivot table on here. You will find all kinds of information that's exactly what you need. You should be able to find about 3 million scripts you can just cut, paste, and modify.MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
davidliv
Starting Member
45 Posts |
Posted - 2004-05-17 : 00:34:11
|
| The crosstab stored procedure does not allow for rollup on the pivot field.I can return:........q1..q2..q3..q4Item 1..22..23..32..10Item 2..20..40..13..41Item 3..50..30..12..55or.......2003.2004.2005.2006Item 1..22...23...32...10Item 2..20...40...13...41Item 3..50...30...12...55What I need is:.............2003.........2004...............2005...........2006........q1..q2..q3..q4.q1..q2..q3..q4.q1..q2..q3..q4.q1..q2..q3..q4Item 1..22..23..32..10.22..23..32..10.22..23..32..10.22..23..32..10Item 2..20..40..13..41.....Item 3..50..30..12..55..... |
 |
|
|
timmy
Master Smack Fu Yak Hacker
1242 Posts |
Posted - 2004-05-17 : 02:09:13
|
| But - how can you have multiple column names????You'll need to have your crosstab column names Q1 2003, Q2 2003 etc, then manipulate in your display layer. |
 |
|
|
|
|
|