Hi
I have a query which produces effectively a pivottable. Is there any way I can dynamically assign the column headings ie the code on each line after AS rather than hard coded as I have currently
Extract of Current SP
CREATE PROC dbo.FairValeSummaryPivot
@.BatchRunID INT
AS
SET NOCOUNT ON
SELECT
MIN(CASE WHEN Tn = '1' THEN PVBalance ELSE 0 END) AS 'Tn1 - Tn0' ,
MIN(CASE WHEN Tn = '0' THEN PVBalance END) AS 'Tn0 - Tn-1' ,
MIN(CASE WHEN Tn = '-1' THEN PVBalance END) AS 'Tn-1 - Tn-2',
MIN(CASE WHEN Tn = '-2' THEN PVBalance END) AS 'Tn-2 - Tn-3',
MIN(CASE WHEN Tn = '-3' THEN PVBalance END) AS 'Tn-3 - Tn-4',
MIN(CASE WHEN Tn = '-4' THEN PVBalance END) AS 'Tn-4 - Tn-5',
-- and so on
FROM FVSummary
WHERE BatchRunID = @.BatchRunID
GO
what I would like would be along the lines of
MIN(CASE WHEN Tn = '1' THEN PVBalance ELSE 0 END) AS 'Tn' + Tn + ' - Tn' + Tn-1, ,
Hope this is clear
CheersDynamic SQL is all that comes to my mind from the SQL perspective, but this is really a presentation issue so I think it should be handled at the client rather than in the SQL itself.
-PatP|||Dynamic SQL is the only method of assigning variable column headers. But I would discourage you from doing this because no reporting application (Crystal, Access, Active Reports...) is going to be able to deal with output that has a different layout for each result set.
There is (almost) never a good reason for doing what you are trying to do, and in essence that is why it is difficult to do.|||Do a google on ags crosstab. Also (if it's still out there) RAC for SQL.
Regards,
hmscott
Showing posts with label headings. Show all posts
Showing posts with label headings. Show all posts
Friday, March 9, 2012
Dynamic derivation of Heading - is it possible
Labels:
assign,
code,
column,
database,
derivation,
dynamic,
dynamically,
effectively,
heading,
headings,
hii,
line,
microsoft,
mysql,
oracle,
pivottable,
produces,
query,
server,
sql
Friday, February 17, 2012
dynamic column headings?
Is it possible for Report Services 2000 to accomplish the following. Are there any examples available that i can take a look?
How can I turn rows in a table into column headings in a report. By the way, the user can chose one questions to see the answers for all the Test Takers.
The questions and answers are rows in two seperate tables.
For example, a certain test may have N questions and N answers. I would like to make the questions the column headings and the answers the rows. Into something like this.
Test Taker Questions 1 Questions2 Questions3 QuestionsN+1
Mike Jay Answer1 Answer2 Answer3 AnswerN+1
Jon Doe Answer1 Answer2 Answer3 AnswerN+1
etc....
Can anyone suggest a solution or documentation?
Thank you,
yadgor2000
Try using a matrix. You can easily do this in VS.Net.
Subscribe to:
Posts (Atom)