ASP Forum
Sorting/searching by letter
alexz33 | Posted 7:25am 27. May 2008 Server Time |

Hi All,
I'm creating a searchable employee DB.
one of the option I want to enable is search by First names
starting by Letter.

How would I fix the query

SQL = "SELECT * FROM qemps WHERE (((emps.Firstname) ....))"

Thanks to all in advance
probinu | Posted 10:21am 27. May 2008 Server Time |

I am a little confused by the statement starting with the letter.  I assume you mean if you enter 'a' you sould like all the a names to return?

Then it looks like this:

Select * From qemps WHERE emps.firstname LIKE 'a%'
alexz33 | Posted 9:29am 28. May 2008 Server Time |

I tried that but it was returning more then i needed.
What ended up dpoing was creating a query and trimed all the first names to only the first letter
FN: Trim(Mid([firstname],1,1))
Then I do the select where firsnme = 'A'
and it works.
WizzKidd | Posted 12:31am 12. June 2008 Server Time |

alexz33, your method would work, but it can be heavy on the server.  If you had a database of 1 million names, it would query the 1 million users, get all their names, then cut off everything except the 1st character, then query the database again for all the names starting with (in your example) 'A'.

I dont see why the method probinu suggested wouldnt work (apart from the possible typo or the possibility of it not matching the lowercase 'a')... ao try:

SELECT * FROM qemps WHERE UCASE(qemps.firstname) LIKE 'A%'


- Neil-One (aka WizzKidd)
- http://www.promotioncity.co.uk


Reply to Post Sorting/searching by letter



Back to Forum Page