Solved

Ignore Case in DB2 SQL

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now