Solved

Ignore Case in DB2 SQL

Posted on 2012-03-28
2
1,890 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:
daveslash earned 500 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 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