Page 1 of 1

Select like number

Posted: Mon Mar 22, 2004 7:06 pm
by doeboy
I have a query that allows users to seach by the first letter of a list. I would like for them to search by numbers if there are any in the list.

Current code:

SELECT FROM WHERE field LIKE '$letter%'

The letter is very easy (because it is one letter) There are 10 numbers (0-9).

Any thoughts?

Posted: Mon Mar 22, 2004 7:20 pm
by coreycollins
I don't really understand what you're asking... There are 26 Letters? Are you looking to search for a whole number. For instance, if 123 is on the database you want to search for 123 and not get 12? Let us know some more information. Maybe how you have it laid our and we can help you.

Posted: Mon Mar 22, 2004 7:24 pm
by doeboy
No. So I have a list of names. Users can filter the list based on letters. So show all names that start with the letter c.

I have that part down. However I have another list where they might be needing to filter by numbers. So rather than clicking on A-Z, they could click on a # sign and the list would be filtered to show only results that start with a number.

Posted: Mon Mar 22, 2004 7:43 pm
by coreycollins
Oh ok that makes sense now.

This is the only way I can come up with how to do what you want right now. There is probably a better way but this is all I could come up with right now and this should work for you.

Code: Select all

SELECT foo FROM bar WHERE foo LIKE '1%' or '2%' or '3%' or '4%' or '5%' or '6%' or '7%' or '8%' or '9%' or '0%'

Posted: Tue Mar 23, 2004 11:01 am
by Weirdan
here is another way:

Code: Select all

SELECT foo FROM bar WHERE left(foo,1) between '0' and '9'

Posted: Tue Mar 23, 2004 12:34 pm
by coreycollins
ahh I was trying to think how to do that Weirdan. I knew there was an easier way.