Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL Select between letters R and Z

Posted on 2014-01-18
5
Medium Priority
?
2,085 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 46

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 2000 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 46

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

618 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