Nested if"S

  • Hi

    I figured I'd put this out there before I leave for work...

    looking to see if I can do a nested if like this:

    if value1 = '1' and value2 = '2' then 'A'

    if value1 = '1' and value9 = '2' then 'B' else

    if value99 = 'l' and value9 = 'x' then 'C' end as?

    What I'm trying to do is find values between 2-3 fields then assign a code.

    also one supersede the other , so if first and second if conditions are met i want the first if value

    Thanks In Advance

    Joe

  • Hi

    If you're trying to do this in T-SQL then what you need is a case statement.

    SELECT

    CASE

    WHEN value1 = 1 AND value2 = 2 THEN 'A'

    WHEN value1 = '1' and value9 = '2' then 'B'

    WHEN value99 = 'l' and value9 = 'x' THEN 'C'

    ELSE '<CatchAllValue>' -- Optional

    END

    FROM

    foo

    WHERE

    bar = <condition>

    Hope that helps.

    Thanks,

    Simon



    MCSE: Data Platform
    MCSE: Business Intelligence
    Follow me on Twitter: @WazzTheBadger
    LinkedIn Profile: Simon Osborne

  • Thanks Simon

    Works great..

    Bad week I should have known that...

    Thanks Again

  • No worries... we all have them.



    MCSE: Data Platform
    MCSE: Business Intelligence
    Follow me on Twitter: @WazzTheBadger
    LinkedIn Profile: Simon Osborne

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

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