Solved

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

Posted on 2014-02-13
4
1,234 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

861 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