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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-06-24 : 07:24:23
|
| Sheryl writes "I read robvolk's article on 'Dynamic Cross-Tabs/Pivot Tables' with much interest and just wanted to ask if a solution for multiple pivot columns was ever produced? I have searched all over the manuals and Internet but cannot find, or figure out, how to do a cross-tab that has multiple pivot columns. My problem is that I have a table likeCode1 Code2 Description Machine Hours OccursAA AB Drive Belt 05 1.2 2AA CB Air System 05 0.6 1AA AB Drive Belt 06 2.4 1etc.I would like to do a cross tab with pivot columns for the Hours and Occurs for EACH machine (which varies depending on input parameters entered). For this data, the result set should look likeCode1 Code2 Description M05_Hrs M05_Occ M06_Hrs M06_OccAA AB Drive Belt 1.2 2 2.4 1AA CB Air System 0.0 0 0.6 1Part of my problem in coming up with a solution is that the number of different Machines (thus pivot columns) varies and is unknown until runtime. So, I could have Hours and Occurs for 2 machines, or 6. I am not yet a sophisticated SQL user and am having the hardest time coming up with a solution. Is this even possible? Any ideas?" |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-06-24 : 07:41:30
|
| see my comment towards the end; i present an alternate (but similiar) proc that does exactly what you're looking for.- Jeff |
 |
|
|
|
|
|