Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7700677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:45:53+00:00 2026-05-31T22:45:53+00:00

Simple question: I need a solution so that I can find, lets say names,

  • 0

Simple question:

I need a solution so that I can find, lets say names, between A-F, INCLUDING all names that start with F.

If you use BETWEEN or A >= value <= F you find out that it stops at F. So I am posting this for suggestions.

NOTE:
User will see 2 textboxes that accept a range user can type. The user refines how far to go in F boundary as such: User types in ‘Fa’ means the result should return: Fauder, Fail, Famber, … etc

I have currently 2 solutions but there’s got a be a better way.

Solution 1:
This will add 1 to outer boundary but may include result if there’s a name that is single ‘G’, highly unlikely though.
WHERE name >= ‘A’ AND <= CHAR(ASCII(‘F’) + 1)

Solution 2:
This solution appends last letter of alphabet field length times.
WHERE name >= ‘A’ AND <= ‘FZZZZZZZZZZZZZZZZZZZZZ’

Although the above solutions are workable, my search can be refined as such:
A to Fs (should give me everything from A to and including Fs….). With this solution #1 is broken since it works with single ascii.

Suggestions are welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:45:54+00:00Added an answer on May 31, 2026 at 10:45 pm

    In a comment you expand the requirement to include A – Fxxx.

    SET @start = 'A'
    SET @end   = 'Fxxx'
    
    SELECT
      *
    FROM
      table
    WHERE
      (name >= @start AND name < @end)
      OR (name LIKE @end + '%')
    

    Note that this does not include functions on the name field; such functions prevent range seeks on indexes. However, the inclusion of the OR degrades the index seek too. Although it’s extra code, this actually can be more performant is some cases…

    SELECT
      *
    FROM
      table
    WHERE
      (name >= @start AND name < @end)
    
    UNION ALL
    
    SELECT
      *
    FROM
      table
    WHERE
      (name LIKE @end + '%')
    

    EDIT

    In hindsight, your Solution 2, although you don’t like it, is probably the best.

    Turning Fxxx to FxxxZZZZZZZZZZ is simple enough with STUFF(), provided that you know the max string length, which you should do as the database is yours.

    It doesn’t have any functions on the name field, and it doesn’t use an OR in the WHERE clause. Which means that you get a pure range seek on any index.

    Performance wise, I do not think you can improve on this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think my question is quite simple, but I can't find a solution. I
Alright simple question I have integriters like 5 188 4634 And they all need
This is a simple question which makes it painfully obvious that I need to
I have a simple question that I assume does not have a simple solution.
Hi all SQL Server Blackbelt masters out there. I have a simple question that
Simple question but i need it :) $query = SELECT * FROM `set` WHERE
I guess this is a simple question. I need to do something like this:
I`m a total newbie in php, so sorry for my simple question. Need to
Simple enough question I am sure. Using MFC C++, what header do I need
For the purpose of the question I need to create a simple fictitious scenario.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.