Solved

Pivot value from a table

Posted on 2013-07-01
1
277 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 59

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

735 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