Closed Thread Icon

Topic awaiting preservation: sql using 'like' (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=26463" title="Pages that link to Topic awaiting preservation: sql using &amp;#039;like&amp;#039; (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: sql using &#039;like&#039; <span class="small">(Page 1 of 1)</span>\

 
slim___shady
Nervous Wreck (II) Inmate

From: canada
Insane since: Aug 2002

posted posted 08-16-2005 05:04

Can someone help me out with using SQL's 'LIkE'

It seems that _ (the underscore) is used as a wildcard for a single character when used in a select statement like the following

select * from tablename where columnname like '_r%'

How would I use 'like' to display records starting with _ (underscore).

I have a table with 2 columns - usernames and phonenumbers. Usernames can start with any alphabet including _(underscore). If I want to display usernames starting with a certain letter, say c, I'd use

select * from tablename where username like 'c%'

Now i need to display usernames that start with _(underscore). What is the correct way to do it coz

select * from tablename where username like '_%'

does not work

Thanx for reading

hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana, USA
Insane since: Aug 2000

posted posted 08-16-2005 07:21

use '\_%' to look for anything that starts with '_'

use '\%' to looks for somthing that contains '%'

.



-- not necessarily stoned... just beautiful.

slim___shady
Nervous Wreck (II) Inmate

From: canada
Insane since: Aug 2002

posted posted 08-16-2005 14:58

thanx for the reply hyperbole but it's still not working

previously with select * from tablename where columnname like '_%' i was getting all the records

Now with select * from tablename where columnname like '\_%' i am getting no records.

Would like to add that I am using Access 2002 with ASP for scripting, if that makes any difference. Any further help would be much appreciated

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 08-16-2005 16:41

Access is weird in that regard

quick googling for 'access microsoft wild card escape' lead to this

select * from tablename where columnname like '#_%' ESCAPE '#'
with # being the escape character here (usually, it's simply a \)

so long,

->Tyberius Prime

« BackwardsOnwards »

Show Forum Drop Down Menu