Solved

Pivot value from a table

Posted on 2013-07-01
1
280 Views
Last Modified: 2013-07-07
Hi Experts,

I have attached an excel file. The top resultset is the way the
result gets displayed before the pivot. The second is
after the pivot is applied. I have a wuery currently that gives me
the second resultset after the pivot.

Below is the current query.



Here's what I want to do. I would want to get these values
from a table as there is a table that contains the values in [5],[-5],[1],[-1] that
I have hardcoded in pivot. I have commented out a field in the query as
Select *from tbl1. So here's basically what I am looking at

PIVOT
(
sum(maintab.amt)  
FOR maintab.scendes in (Select *from tbl1).

Not sure if it is possible or not but your help will be highly
appreciated.
pid.xls
0
Comment
Question by:Josh2442
[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 60

Accepted Solution

by:
Kevin Cross earned 305 total points
ID: 39291876
Hi. The value list in the PIVOT operator has to be static, so you will need to use dynamic sql to get list from a query. An alternative is to PIVOT in a client reporting tool, such as Excel.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Suggested Solutions

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

732 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