Home Forums SQL Server 7,2000 T-SQL If statement in WHERE clause of Stored Procedure RE: If statement in WHERE clause of Stored Procedure

  • childhood (10/31/2015)


    The near same "hydera" but I have 2 variables varCategory, varName and I need condition AND beetween

    varCategory AND varName below:

    declare @varCategory int

    declare @varName varchar(50)

    Select * from tblparticipants

    where

    IF varCategory = NULL then

    --ignore where clause

    IF varCategory = 1 or 2 or 3 THEN

    --varCategory = @varCategory

    IF varName = NULL then

    --ignore where clause

    IF varName != NULL then

    AND varName = @varName (I mean, where clause varCategory AND varName)

    END IF

    In above, how must we do it? Please help me.

    Gosh. This whole thread has been about how to do it. At least try.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)