Solved

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

Posted on 2014-02-13
4
1,241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Detach & Attach 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.
I have a large data set and a SSIS package. How can I load this file in multi threading?
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
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

749 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