Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting result rows into columns....interesting dillema

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
say you have a result set that goes like this:
StudentID StudentType
----------------------
1 0
2 1
3 2
4 0
5 1
6 2

and I want to get:
Type1StudentID Type2StudentID
------------------------------
2 3
5 6

without writing a cursor, how can I do this?

 
Could you clarify the logical relationship between the two sample data sets? Malcolm
 
Clarification:
1st record set represents a table (say student)
that has 2 attributes (StudentID PK) and Student Type
type can only be on of 3 (0--Day 1--Night 3 Neither)

Now, what I want to do is get all students in each of the type categories in 1 query...
i.e. Get all night students (as nightST), and day Students (as datST) and neither as Neither

Thanks for your help
 
If you are using Oracle, this might help you :

select decode(StudentType,1,StudentID,null) Type1,
decode(StudentType,2,StudentID,null) Type2,
decode(StudentType,3,StudentID,null) Type3
from TableName;
 
"Now, what I want to do is get all students in each of the type categories in 1 query... "
Do you mean summarized is some way, such as a count? Or do you just want the query to show a more descriptive name for the various student types? Or, as Beena showed above (for Oracle), do you want individual columns for each student type, populated with Student ID's?
Malcolm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top