IF ELSE... what about ''OR'' ?

  • i would like to use OR, but don't know how to set it up.

    heres what i got so far.

    declare @whatever int

    select @whatever = [myvalue] from

    if @whatever = 'myvalue'

    begin sp_this

    end

    else

    begin sp_that

    end

    what if i want to use OR ?

    if @whatever = 'myvalue' OR 'myvalue 2'

    begin sp_this

    end

    else

    being sp_that

    end

    is some thing like this possible?

    thanks in advance.

    _________________________

  • if (@whatever = 'myvalue') OR (@whatever = 'myvalue 2')

    MohammedU
    Microsoft SQL Server MVP

  • wow that was simple.

    thanks!!

    _________________________

  • OR

    if @Whatever in ('value1', 'value2')

     

    This is more easily expanded.

  • what? with the paren's and all that?

    i noticed you have the (in) instead of (=).

    does that work?

    _________________________

  • See for yourself :

    DECLARE @X AS VARCHAR(10)

    SET @X = 'Test'

    IF @X IN ('t', 't2', 'Test')

    BEGIN

     SELECT 'Hello world'

    END

  • cool! you rock bro!

    _________________________

Viewing 7 posts - 1 through 6 (of 6 total)

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