Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Including Extra Columns in a Pivot

$
0
0

Dear All

With much help from you all in the forums, I have created a pivot in order to display data in my child rows as columns. The output is exactly as I had hoped except for there is an additional field in my table called Curriculum called CurriculumLink which I wanted to use to turn each title into a hyperlink.

WITH Data AS (
	SELECT	S.SubjectDescription, 
			T.TermDescription, 
			C.CurriculumTopic
	FROM	Term  T
		INNER JOIN Curriculum C ON T.TermID = C.CurriculumTerm 
		INNER JOIN [Subject] S ON C.CurriculumSubject = S.SubjectCode
	)
	SELECT	SubjectDescription,
			[Spring Term], 
			[Summer Term], 
			[Autumn Term]
	FROM	Data D
		PIVOT (MIN(CurriculumTopic) FOR TermDescription IN ([Spring Term], [Summer Term], [Autumn Term])) AS PM;

The design of my tables and the outputted data look as follows:

The second table illustrates what I think I need to do in order for me to apply a hyperlink to each CurriculumTopic when rendering in ASP .net.

Is it possible to include these extra columns in a pivot?

Many thanks for your help

Daniel


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>