Solved

Pivot value from a table

Posted on 2013-07-01
1
269 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now