8/12/2019 CDB Between Grtls
1/3
2/27/2014 CDB Software, Inc.
http://www.cdbsoftware.com/whitepapers/cmnews-quarter4-2011.php 1/3
CDB Global//CDB North America// CDB International
HomeNews &Events
Webcasts
Press Releases
White Papers & Articles
About CDB
CDB North America
CDB International
CDB Global
Products & Solutions
Packages
Real Time DB2 Data Management Solution
Real Time DB2 Database Maintenance Solution
DB2 Index Management Solution
DB2 Image Copy Solution
DB2 Partition Management SolutionDB2 Data Propagation Solution
Product List
Support
Policies & Guidelines
Product Compatibility
Onsite Training
News &Notifications
Product Documentation
Technical Bulletins
PTFs & Libraries
Online Training Videos
My Profile
Partners
Become a Partner
Meet Our Partners
Contact Us
Login
White Papers & Articles
4th Quarter 2011
http://www.cdbsoftware.com/supporthttp://www.cdbsoftware.com/supporthttp://www.cdbsoftware.com/become-a-partner.phphttp://www.cdbsoftware.com/become-a-partner.phphttp://www.cdbsoftware.com/supporthttp://www.cdbsoftware.com/supporthttp://www.cdbsoftware.com/supporthttp://www.cdbsoftware.com/supporthttp://www.cdbsoftware.com/onsite-training.phphttp://www.cdbsoftware.com/product-compatibility.phphttp://www.cdbsoftware.com/policies-and-guidelines.phphttp://www.cdbsoftware.com/db2-data-propagation-solution.phphttp://www.cdbsoftware.com/db2-index-management-solution.phphttp://www.cdbsoftware.com/real-time-db2-data-management-solution.phphttp://www.cdbsoftware.com/real-time-db2-data-management-solution.phphttp://www.cdbsoftware.com/about-cdbglobal.phphttp://www.cdbsoftware.com/about-cdb.phphttp://www.cdbsoftware.com/white-papers-and-articles.phphttp://www.cdbsoftware.com/press-releases.phphttp://www.cdbsoftware.com/webcasts.phphttp://www.cdbsoftware.com/webcasts.phphttp://www.cdbsoftware.com/about-cdbglobal.phphttp://www.cdbsoftware.com/about-cdb.phphttp://www.cdbsoftware.com/index.phphttp://www.cdbsoftware.com/index.phphttp://www.cdbsoftware.com/index.phphttp://www.cdbsoftware.com/index.phphttp://www.cdbsoftware.com/supporthttp://www.cdbsoftware.com/contact-us.phphttp://www.cdbsoftware.com/meet-our-partners.phphttp://www.cdbsoftware.com/become-a-partner.phphttp://www.cdbsoftware.com/become-a-partner.phphttp://www.cdbsoftware.com/supporthttp://www.cdbsoftware.com/supporthttp://www.cdbsoftware.com/supporthttp://www.cdbsoftware.com/supporthttp://www.cdbsoftware.com/supporthttp://www.cdbsoftware.com/supporthttp://www.cdbsoftware.com/onsite-training.phphttp://www.cdbsoftware.com/product-compatibility.phphttp://www.cdbsoftware.com/policies-and-guidelines.phphttp://www.cdbsoftware.com/policies-and-guidelines.phphttp://www.cdbsoftware.com/product-list.phphttp://www.cdbsoftware.com/db2-data-propagation-solution.phphttp://www.cdbsoftware.com/db2-partition-management-solution.phphttp://www.cdbsoftware.com/db2-image-copy-solution.phphttp://www.cdbsoftware.com/db2-index-management-solution.phphttp://www.cdbsoftware.com/real-time-db2-database-maintenance-solution.phphttp://www.cdbsoftware.com/real-time-db2-data-management-solution.phphttp://www.cdbsoftware.com/real-time-db2-data-management-solution.phphttp://www.cdbsoftware.com/about-cdbglobal.phphttp://www.cdbsoftware.co.uk/http://www.cdbsoftware.com/about-cdb.phphttp://www.cdbsoftware.com/about-cdb.phphttp://www.cdbsoftware.com/white-papers-and-articles.phphttp://www.cdbsoftware.com/press-releases.phphttp://www.cdbsoftware.com/webcasts.phphttp://www.cdbsoftware.com/webcasts.phphttp://www.cdbsoftware.com/index.phphttp://www.cdbsoftware.co.uk/http://www.cdbsoftware.com/about-cdb.phphttp://www.cdbsoftware.com/about-cdbglobal.phphttp://www.cdbsoftware.com/index.php8/12/2019 CDB Between Grtls
2/3
2/27/2014 CDB Software, Inc.
http://www.cdbsoftware.com/whitepapers/cmnews-quarter4-2011.php 2/3
Which is better? BETWEEN versus =
As all good DB2 developers know, there is frequently more than one way to write a SQL statement to return
the same results. But the performance that is another issue. In this quarters tip, we take a look at
BETWEEN and the equivalent combination of =.
The BETWEEN predicate is easier to understand and code than the equivalent combination of less than or
equal to (=). In past releases, in many cases it was more efficient, too.But today, in most cases, the DB2 Optimizer recognizes the two formulations as equivalent and there usually
is no performance benefit one way or the other.
Performance reasons aside, one BETWEEN predicate is simpler to code and maintain than multiple = predicates. For this reason, I tend to favor using BETWEEN. but not always. Consider the scenario of
comparing a host variable to two columns. Usually BETWEEN is used to compare one column to two
values, here shown using host variables:
WHERE COLUMN1 BETWEEN :HOST-VAR1 AND :HOST-VAR2
However, it is possible to use BETWEEN to compare one value to two columns, for example:
WHERE :HOST-VAR BETWEEN COLUMN1 AND COLUMN2
This statement should be changed to:
WHERE :HOST_VAR >= COLUMN1 AND :HOST-VAR = AND = 'H';
Or we could code MIDINIT BETWEEN 'H' AND 'Z' in place of MIDINIT >= 'H'. Of course, for either of
these solutions to work correctly we would need to know that MIDINIT never contained values that collatelower than the value 'A'.
So, as usual, there is no one size fits all answer to the question!
8/12/2019 CDB Between Grtls
3/3
2/27/2014 CDB Software, Inc.
http://www.cdbsoftware.com/whitepapers/cmnews-quarter4-2011.php 3/3
Contribution by Craig Mullins
Craig S. Mullins, president and principal consultant of Mullins Consulting, Inc., is a data management
strategist, researcher, and consultant. He has nearly three decades of experience in all facets of database
systems development and has worked with mainframe DB2 since V1. You may know Craig from his popular
books: DB2 Developers Guide (with over 1500 pages of in-depth technical information on DB2 for z/OS)
and Database Administration: The Complete Guide to Practices and Procedures (the industrys only
comprehensive guide to heterogeneous database administration). Craig can be reached via his website atwww.craigsmullins.com.
return to white papers
Press Releases
White Papers & Articles
Press Contacts
About CDB
HomeNews & EventsAbout CDBProducts & SolutionsSupportPartnersContact UsLogin Copyright 2012-2014 CDB Software All Rights Reserved. | Legal Disclaimer
CDB Software, Inc.
Toll-Free: 800-627-6561
Phone: 713-588-1778
Fax: 800-627-4232
mailto:[email protected]://www.cdbsoftware.com/legal-disclaimer.phphttp://www.cdbsoftware.com/supporthttp://www.cdbsoftware.com/contact-us.phphttp://www.cdbsoftware.com/become-a-partner.phphttp://www.cdbsoftware.com/policies-and-guidelines.phphttp://www.cdbsoftware.com/real-time-db2-data-management-solution.phphttp://www.cdbsoftware.com/about-cdb.phphttp://www.cdbsoftware.com/webcasts.phphttp://www.cdbsoftware.com/index.phphttp://www.cdbsoftware.com/about-cdb.phphttp://www.cdbsoftware.com/press-contacts.phphttp://www.cdbsoftware.com/white-papers-and-articles.phphttp://www.cdbsoftware.com/press-releases.phphttp://www.cdbsoftware.com/white-papers-and-articles.phphttp://www.craigsmullins.com/Recommended