Results 1 to 6 of 6

Thread: Alphabetical search

  1. #1
    Join Date
    Feb 2003
    Location
    Canada
    Posts
    3

    Alphabetical search

    I have one question about the alphabetical search, I have written a SQL
    "SELECT * FROM name where firstname like 'A%'" to show all the name which are start from A.
    If I want to search from A to Z, do I need to write 26 SQL statements to do that or do I have another better methods to do that?
    That mean when i click on A, it will search all the records that firstname starting from A, when i click on D, it will show all the records that the firstname is only start from D.
    Anyone can help me to solve this problem.
    Thx!

  2. #2
    Join Date
    Nov 2002
    Location
    DE
    Posts
    246
    In T-SQL I would go for a stored procedure which accepts the letter as a parameter:

    CREATE PROCEDURE qseNamesByLetter (
    @letter char (1)
    ) AS

    SELECT * FROM name where firstname like @letter + '%'

  3. #3
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    Did you try this

    SELECT * FROM name where firstname like '[A-Z]%'

  4. #4
    Join Date
    Nov 2002
    Location
    DE
    Posts
    246
    But this will give you all records where the firstname starts with any letter from A to Z, won't it?

    As far as I understand the question it is about a selection based on a single letter...

  5. #5
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    This is just an example, I think the original poster wanted to know of any method to get list of names between a range.

  6. #6
    Join Date
    Feb 2003
    Location
    Canada
    Posts
    3
    Thanks for all guys!
    skhanal, may be my previous post confuse you, I only want to click one letter, and then show the record corresponding to this letter. So I added some explanations to this new post.
    andi_g69, thx for your reply, I will try later.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •