Help with stored procedure IN keyword

  • I have this where clause where I'm passing in a status code and if it's not passed (therefore NULL), status_code <> 10 (or equal to 9 or 11 or 12); if it is passed then i want to search for status_code = 10.  Help pls!

    WHERE status_code

    IN

    CASE @status_code WHEN NULL THEN (9,11,12)

    ELSE (10)

    END

    Btw, I already have this where clause inside an IF statement.

  • You don't need CASE .. WHEN, it's just a simple OR:

    WHERE

      (@Status_code IS NOT NULL AND status_code = 10)  OR

      (@status_code IS NULL AND status_code IN (9,11,12) )

  • ahhh.. makes sense. It worked! Thanks!

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

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