Friday, February 24, 2012

how can i use % with IN Clause?

helo..
i wont to use IN Clause for searching but i do not know how to use % with IN Clause.

like this:
select * from infotbl where infotitle IN('%tree%', 'sun')

this is return err.

what i have to do?

Hi,

You can not use IN with '%%' for searching column values including a certain criteria

select * from infotbl (nolock) where infotitle IN ('%tree%', 'sun')

This will look for rows whose infotitle column value equals exactly '%tree%'

But you can use LIKE with '%%' to search values including "tree"

select * from infotbl (nolock) where infotitle LIKE '%tree%'

Eralper

http://www.kodyaz.com

|||

If you know how many values you want to check for then you could simply take the example below and modify as appropriate.

Chris

SELECT *

FROM infotbl

WHERE (infotitle LIKE '%tree%'

OR infotitle = 'sun')

No comments:

Post a Comment