Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Ignore Case in DB2 SQL

Posted on 2012-03-28
2
Medium Priority
?
2,091 Views
Last Modified: 2012-03-30
Hi Everyone,

I'm trying to design a query/CASE statement that will ignore the case of a field. Example: 'APPLE' and "Apple'.
I would like to combine the following two separate statements into one statement.
WHEN FOOD = 'APPLE'                  THEN ' Fruit'
WHEN FOOD = 'Apple'                   THEN ' Fruit'

Thanks in advance!

Mark
0
Comment
Question by:Mark1M
2 Comments
 
LVL 18

Accepted Solution

by:
Dave Ford earned 2000 total points
ID: 37779702
The classic answer to this dilemma involves applying the UPPER function:

WHEN Upper(FOOD) = 'APPLE'  THEN ' Fruit'

Alternately, some "flavors" of DB2 support defining your data with "case-insensitive sort-sequence", but that's significantly more complex. Let me know if you want more details on that one.

HTH,
DaveSlash
0
 
LVL 37

Expert Comment

by:momi_sabag
ID: 37780487
note that using such a function can significantley hurt the performance of the query because it might cause db2 to not use an index on the food column
if you only have two options (all upper case letters or the first letter is upper case and the rest are lower case) you might be better off using the in predicate
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

916 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