Solved

Ignore Case in DB2 SQL

Posted on 2012-03-28
2
1,860 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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 (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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