Home Forums SQL Server 2005 T-SQL (SS2K5) how to check multiple combinations of a variable for null RE: how to check multiple combinations of a variable for null

  • If your first three parameters are simply the on/off values and the fourth parameter is the actual search string then

    where

    (@pIn_Product = 1 and ProductName like @searchString) or

    (@pIn_StockUnit = 1 and StockUnit like @searchString) or

    (@pIn_ProductCode = 1 and ProductCode like @searchString);

    For performance reasons, to be sure to use any indexes correctly, I might write the store proc to use separate queries.

    if @pIn_Produc = 1

    begin

    select blah

    from something

    where productName like @searchstring

    end

    else if @pIn_StockUnit = 1

    begin

    select blah

    from something

    where StockUnit like @searchstring

    end

    else if @pIn_ProductCode = 1

    begin

    select blah

    from something

    where ProductCode like @searchstring

    end

    Are Bruce and I close?

    You also have potential solutions in dynamic SQL, but any way you go, you have to at some point list and test all the parms by name.

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills