problem with '=' in case statement

  • select id,

    idnum,

    max(dischargedate) as dischargedate,

    case when (race_2 is null) or (race_other is null)

    then racecode= finalrace

    when racecode = 'W' and race_2 = 'H'

    then Finalrace = 'H'

    end as 'Finalrace'

    from #All

    group by dischargedate,id,

    idnum,race_2,race_other,racecode

    giving me error message

    Incorrect syntax near '='.

    could you please help?

    Thanks.

  • hbanerje (4/25/2011)


    select id,

    idnum,

    max(dischargedate) as dischargedate,

    case when (race_2 is null) or (race_other is null)

    then racecode= finalrace

    when racecode = 'W' and race_2 = 'H'

    then Finalrace = 'H'

    end as 'Finalrace'

    from #All

    group by dischargedate,id,

    idnum,race_2,race_other,racecode

    giving me error message

    Incorrect syntax near '='.

    could you please help?

    Thanks.

    The structure of your case statement is in correct. You only include the value in the statement without an equal sign. select id,

    idnum,

    max(dischargedate) as dischargedate,

    case when (race_2 is null) or (race_other is null)

    then racecode

    when racecode = 'W' and race_2 = 'H'

    then 'H'

    end as 'Finalrace'

    from #All

  • Thank you.

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

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