Solved

Displaying data from the same table value but in a different column

Posted on 2014-02-13
4
1,199 Views
Last Modified: 2014-02-17
I am trying to write a report where a particular record can have more than one record associated with it on another table. The problem is I want to see it for that same record in a different column so that we can see it all as a bigger picture. I have tried to use aliases but I do not know how to get the data to appear inside those columns. Below is the main query but I also want to add the information for activity value description with a different activity 'STUD' to go along with 'FINSUP'

select c.label_name, c.status, a.activity_value_desc as Financial_Support_Type, a.activity_value_desc as student_status 
FROM contacts C

INNER JOIN contact_categories cc ON cc.contact_number = c.contact_number 
INNER JOIN activity_values A ON a.activity_value = cc.activity_value 

WHERE cc.activity = 'FINSUP' 

ORDER BY c.label_name

Open in new window

0
Comment
Question by:MSSC_support
  • 3
4 Comments
 

Author Comment

by:MSSC_support
ID: 39856568
As you can see in the image below, I have seperated out the columns I want but I want the last column to display the information for the activity_value 'STUD' rather than the same information in ' FINSUP'

picture of table output
0
 
LVL 11

Accepted Solution

by:
John_Vidmar earned 500 total points
ID: 39856741
Add fields you need into the select-clause from tables aliased with dd and/or b:
SELECT	c.label_name
,	c.status
,	a.activity_value_desc as Financial_Support_Type
,	a.activity_value_desc as student_status 
FROM	contacts		c
JOIN	contact_categories	cc	ON	cc.contact_number = c.contact_number 
					AND	cc.activity = 'FINSUP' 
JOIN	activity_values		a	ON	a.activity_value = cc.activity_value 
JOIN	contact_categories	dd	ON	c.contact_number = dd.contact_number
					AND	cc.activity = 'STUD' 
JOIN	activity_values		b	ON	b.activity_value = dd.activity_value 

ORDER
BY	c.label_name

Open in new window

0
 

Author Comment

by:MSSC_support
ID: 39858450
Hi John,

The above failed to bring back any results. I may see what I can do with it to however.

Thanks,
Jayson
0
 

Author Closing Comment

by:MSSC_support
ID: 39865104
I managed to get it working using the segment of SQL provided.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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.
In this article I will describe the Copy Database Wizard 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.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

758 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

19 Experts available now in Live!

Get 1:1 Help Now