?
Solved

Pivot Query

Posted on 2013-01-29
1
Medium Priority
?
324 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 2000 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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

There are some very powerful Dynamic Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a di…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

771 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