Nested CASE in SQL
There's nothing especially difficult about nesting CASE statements in SQL, but I guess it could be confusing sometimes.
Here's an example:
when 'C' then
case control
when 1 then
case phase
when 1 then 'Initial Diary'
when 2 then '8 week pause'
when 3 then 'Ending Diary'
else 'unknown'
end
else
case phase
when 1 then 'Initial Diary'
when 2 then 'Learing Modules'
when 3 then 'Ending Diary'
else 'unknown'
end
end
when 'P' then 'Parent Modules'
end as phaseText


