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:

case [group]
   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

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)

Psykel blog uses BlogCFC (by Raymond Camden). Layout design inspired by arcsin