case inside case Is it Possible?

  • Hi,

    I am trying to do the case statement like this but it is giving error

    select case when frequency = 'biweekly' then case when sum(hours) > 80 then 1 else sum(hours)/80 end

    when frequency = 'weekly' then case when sum(hours) > 40 then 1 else sum(hours)/40 end

    end

    Please let me know.

    Thanks,

    Sridhar.

  • It is working...It is my fault with the syntax

  • It does not give any error.

    declare @frequency nvarchar (50)

    declare @hours real

    set @frequency = 'biweekly'

    set @hours = 45

    select case when @frequency = 'biweekly' then

        case when @hours > 80 then 1 else @hours/80 end

       when @frequency = 'weekly' then

        case when @hours > 40 then 1 else @hours/40 end

    end

    This works absolutely fine.

    Look for an error in another place.

    _____________
    Code for TallyGenerator

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

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