Friday, March 5, 2010

Oracle multiple case select statement

In a table, I have 3 columns (checkbox1, checkbox2, checkbox3) representing values about "Where does the knowledge come from?".
if checkbox1 == 1, that means the knowledge comes from "My_Course",
checkbox2 -> Internet,
checkbox3 -> Staff.

if the checkbox1,2,3 == 0, then it's empty string.

Basically I want to concatenate values from multiple columns into one value "Know_from_where":

select student_type,
(case checkbox1
when 1 then 'My_Course, '
when 0 then '' end ) ||
(case checkbox2
when 1 then 'Internet, '
when 0 then ''
end ) ||
(case checkbox3
when 1 then 'Staff, '
when 0 then '' end ) Know_From_Where
from infolit

No comments:

Post a Comment