Solved

Pivot Query

Posted on 2013-01-29
1
321 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

809 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