Nested case statements

  • Is it possible to write nested case statements. would somebody  please provide a sample statement for that?

    thanks,

    Prema

  • Yes, it's possible. e.g.

    select

        id,

        case when id between 1 and 7 then

                    case when id = 1 then 'one' when id = 2 then 'two' else 'between three and seven' end

             when id between 8 and 10 then

                    case when id = 8 then 'eight'

                         when id = 9 then 'nine'

                         when id = 10 then 'ten'

                    end

             else 'bigger than ten'

        end as 'pointless description'

    from sysobjects

    Ryan Randall

    Solutions are easy. Understanding the problem, now, that's the hard part.

  • Thanks, I solved my problem

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply