Solved

Pivot Query

Posted on 2013-01-29
1
322 Views
Last Modified: 2013-01-30
Please see attached ON the DATABASE TABLE TAB.  This is my source DATA.
Please see attached ON the How it Should look TAB.  
Mapping FROM the DATABASE TABLE
Occurence = Wall

COLUMN 1 = The multiplier WHERE Priority=1 FROM the databasetable
COLUMN 2 = The multiplier WHERE Priority=2 FROM the databasetable

Please see attached ON the What Query returns tab

This is not what I want.  I need TO PIVOT the priority As the columns AND THEN DROP the multiplier VALUES IN each COLUMN according TO priority

Here is my query.  Can someone please take a look and tell me what I should do to make this work.  If possible, could you provide some code.  

Thanks.


select Occurence AS Wall, Multiplier, [1], [2]
from (
      select Occurence, Multiplier,Priority, row_number() over (partition by Occurence ORDER BY Occurence) rn
      from tblCadenceStrategydetails_test
) o
pivot(Max(Priority) for rn in ([1], [2])) p
ORDER BY Occurence


I am really in a bind to get this working.  Any help would be greatly appreciated.
pivotquestion.xlsx
0
Comment
Question by:sherbug1015
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 25

Accepted Solution

by:
chaau earned 500 total points
ID: 38833480
This is what you are after:

select Occurence AS Wall, [1], [2]
from (
      select Occurence, Multiplier, Priority
      from tblCadenceStrategydetails_test
) o
pivot(MAX(Multiplier) for Priority in ([1], [2])) p
ORDER BY Occurence

Open in new window


SQL Fiddle
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Incremental load example 2 56
CROSS APPLY 4 61
create insert script based on records in a table 4 28
LAG_ROWID - how do I get the right order using this query? 2 22
Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question