finding records with an underscore using like

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

finding records with an underscore using like

Joe Noon
I need to find all records where login has an underscore in them.  I
know it has something to do with ESCAPE, since _ matches a single
character, but I cant seem to get the syntax correct.  Here is what im
intending to do, even though this obviously doesnt do it:

SELECT * from users where login LIKE '%_%';

Can anyone suggest a proper statement that escapes the underscore, so
the above will work as intended?

Thank you!

Joe Noon
Reply | Threaded
Open this post in threaded view
|

Re: finding records with an underscore using like

Puneet Kishor

On Oct 7, 2005, at 10:21 PM, Joe Noon wrote:

> I need to find all records where login has an underscore in them.  I
> know it has something to do with ESCAPE, since _ matches a single
> character, but I cant seem to get the syntax correct.  Here is what im
> intending to do, even though this obviously doesnt do it:
>
> SELECT * from users where login LIKE '%_%';
>
>

SELECT * FROM users WHERE login LIKE '%\_%'  ESCAPE '\'

note: you can use an escape char of your choice.

--
Puneet Kishor