Solved

Pivot Query

Posted on 2013-01-29
1
316 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
1 Comment
 
LVL 24

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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
In this article I will describe the Backup & Restore 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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now