Solved

Pivot value from a table

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

791 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