Solved

SQL Select between letters R and Z

Posted on 2014-01-18
5
1,700 Views
Last Modified: 2014-01-19
I'm trying to use

Select title from mylist where title between 'r' and 'z'

It selects all the r's but I dont see any title beginning with 'z'.
How do I make this command inclusive for the last letter as well?
0
Comment
Question by:arthurh88
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 39791635
Hi Arthur,

"between" is inclusive of the two delimiters.  In your example, all of the letters between 'r' and 'z', including 'r' and 'z'.

I suspect that any title that starts with 'z' is more than once character in length.  In that case, the name would not be between 'r' and 'z' as the sort order would place it after 'z'.

Try this:

  where substring (title, 1, 1) between 'a' and 'z'.


You might next stumble onto a case issue.  If so, make sure that you call the lower() function on the first character of the title.

  where lower (substring (title, 1, 1)) between 'a' and 'z'.


Good Luck,
Kent
0
 
LVL 29

Accepted Solution

by:
IrogSinta earned 500 total points
ID: 39791643
You can also do something like this:
between 'r' and 'zzzzz'

Ron
0
 

Author Closing Comment

by:arthurh88
ID: 39791711
yes that worked awesome.   between 'a' and 'ezz'  thanks!
0
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 39792046
I hate to see people use the wrong solution because it codes easier.

As soon as you have a title that starts with 'ezzanything' that doesn't work.  Nor does it work if the title contains mixed case letters.  It may work in this one specific application, but it's a poor habit to get into.
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 39792293
@arthurh88
You should have used a few more z's just in case you do have a title that starts with ezz.  In addition, if you're titles are in both Upper and Lower case, you will run into a problem.  You should add the Lower function to your Where condition as Kdo said.

The benefit of using zzzzz's in a range is that it allows you to define your delimiters more specifically such as shown below:

BEG_RANGE      END_RANGE
AAAAAAAAAA      GLIDZZZZZZ
GLIEAAAAAA          POGUZZZZZZ
POGVAAAAAA        ZZZZZZZZZZ
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how the fundamental information of how to create a table.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question