Use IN and LIKE in WHERE Clause at Same Time

  • Is it possible to use the LIKE and IN in the WHERE clause?

    I have a where clause that's like this:

    WHERE (Customers.CompanyName = @Company) and

    (ChangeLog LIKE '%' + @product + '%' + '%1%')

    This is good when selecting one product, but we have several products and wanted to use IN but with LIKE at the same time.

    Thanks for any possible help.

    -Gonzalo

  • The two operators can't really be combined. Your best bet would be to use OR conditions instead of an IN function. so you would have:

    WHERE (Customers.CompanyName = @Company) and

    ( (ChangeLog LIKE '%' + @Product1 + '%' + '%1%') OR

    (ChangeLog LIKE '%' + @Product2 + '%' + '%1%') OR

    (ChangeLog LIKE '%' + @Product3 + '%' + '%1%') )

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

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