CASE statement help

  • How can I assign the same value (ie. 1) to two different conditions, within the CASE statement?

    SELECT C.Warehouse_Aisle =

    CASE BS.Warehouse_Segment

    WHEN 'Gourmet' then 1

    WHEN 'Commercial' then 1

    WHEN 'Consumer' then 2

    END

    FROM Compartment C

    JOIN Business_Segment BS

    ON C.ID = BS.ID

    At this point this select statement will populate all Commercial rows with NULL, rather than 1 values.

  • What are you trying to do exactly?

  • You're saying "assign" and "populate" but you're only running a select. Are you trying to update?

    UPDATE

    C

    SET

    C.Warehouse_Aisle =

    CASE BS.Warehouse_Segment

    WHEN 'Gourmet' then 1

    WHEN 'Commercial' then 1

    WHEN 'Consumer' then 2

    END

    FROM Compartment C

    JOIN Business_Segment BS

    ON C.ID = BS.ID

    ______________________________________________________________________________
    How I want a drink, alcoholic of course, after the heavy lectures involving quantum mechanics.

  • Ninja's_RGR'us (8/3/2011)


    What are you trying to do exactly?

    We don't get e-mail notifications when you edit your question like that. You get faster help when replying to the question instead of editing... just fyi.

  • OK, Ninja, understood about edit.

    Todd, I was going to use that SELECT statement within a CASE statement (inside USING clause).

    I was foolish with my question, however, because ID is an identity column, which can't accept two seperate values for the same ID. Bad question, infact. I am sorry.

    I do however, have another question....will I will post seperately.

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

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