Click to See Complete Forum and Search --> : Results of several fields in one column


srinika
September 20th, 2005, 03:52 PM
Hi All,

I have a table which has several fields which gives some values if queried. I need to combine the effect and show the results by a query.

Table fields and data are as follows:

StudentID Elementary Middle High
STD00012 False Y N
STD00117 True N N
STD00044 False Y N
STD00324 False N Y


I can't change the table structure

I Need the Output (of a query as follows)
STD00012 Middle
STD00117 Elementary
STD00044 Middle
STD00324 High

Thanks for any help

hmc
September 21st, 2005, 03:01 AM
You want to have a text as a result that is not in the table you mention. You should add a table which contains the texts Elementary, Middle and High.
It is even a better idea to change the table and use something like this:


TypeID TypeName
1 Elementary
2 Middle
3 High


Your table contains the following:

StudentID TypeID
STD00012 2
STD00017 1

olivthill
September 21st, 2005, 08:02 AM
Hi. Sorry for being late.
Here is the query you need. I have tested it with MS-Access, and it should work also on other databases.
SELECT StudentID, 'Elementary' as 'Section'
FROM T_student
WHERE Elementary = True
UNION
SELECT StudentID, 'Middle' as 'Section'
FROM T_student
WHERE Middle = 'Y'
UNION
SELECT StudentID, 'High' as 'Section'
FROM T_student
WHERE High = 'Y'
ORDER BY StudentID;

srinika
September 21st, 2005, 08:36 AM
Thank you So much.

Answer is perfect.