Case-Insensitive Queries using ODBC on IBM i

ODBC with Db2 for IBM iWhen querying for character data using SQL, case matters. “A” is not equal to “a”. Even so, you might want to find all matches, whether uppercase, lowercase, or mixed case.

If you use ODBC, the IBM i driver offers keywords to provide case-insensitivity.

We will demonstrate using the sample table QIWS.QCUSTCDT, which contains a column called CITY that includes a mixed case value, ‘Dallas’.

I can test using the standard isql command, specifying my default ODBC Data Source Name (DSN), which is *LOCAL:

From the isql command line I search for uppercase DALLAS. I get back no matching rows:

To create a case-insensitive connection, I then edited /QOpenSys/etc/odbc.ini and added an additional DSN called NOCASE:

By adding the combination of keywords SortWeight = 0, SortSequence = 2, and LanguageID = ENU (use your own language), this DSN becomes case-insensitive.

Then I test with my new NOCASE DSN:

Testing whether we can search for uppercase DALLAS against mixed case Dallas:

It worked!

Note: If, instead of editing your DSN, you provide connection string keywords to your application directly, the keywords are SORTWEIGHT, SORTSEQUENCE, and LANGUAGEID.

For more information on connection strings and DSNs, see ODBC Connection Strings for IBM i Db2.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.