Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inclusive Alphabetical range in query expression 3

Status
Not open for further replies.

Vie

Technical User
Jan 22, 2004
115
US
This is probably a pretty stupid question but I'm trying to get a query to return a range of names, for instance, all people whose last names begin with A through all those people whose last names begin with P. No matter what expression I use, it seems to be up to P and not through P.

Between A And P GIVES A up to P
>=A And <=P GIVES A up to P
>A And <=P GIVES A up to P

Anybody know how to do this? I'm just not getting it.

Vie
 
This example provides A through P including P...

SELECT tbl.LASTNAME
FROM tbl
WHERE (((Left([LastName],1)) Between "A" And "P"))
ORDER BY tbl.LASTNAME;
 
Hi Vie,

Perhaps a bit of explanation would help.

I guess you are checking the whole of LastName, rather than the first character. The problem with this is that "POE" or "PEABODY" or whatever are all greater than "P". You can go with sxschech's solution or change what you are doing to be [blue]< "Q"[/blue]

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
Or you could use LIKE
Code:
SELECT tbl.LASTNAME
FROM tbl
WHERE [LastName] LIKE '[A-P]*'))
ORDER BY tbl.LASTNAME
 
All good suggestions and all work. And Tony, thanks for the explanation - now I get it! So, basically if I add a z (eg Pz) then all the last names beginning with P will be returned.

Thanks sxschech, Tony, and Golom!
Vie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top