I'm executing the below DB2 SQL via SQL Server (so needs to be in DB2 SQL):
exec ('
select
TRIM (vhitno) AS "Item",
TRIM (mmitds) AS "Description",
TRIM (SUBSTRING (vhitno,12,4)) AS "Size",
vhalqt AS "Available"
from m3fdbtest.oagrln
left outer join m3fdbtest.mdeohe
on vhcono = uwcono
and vhcuno = uwcuno
and vhagno = uwagno
and vhitno = uwobv1
left outer join m3fdbtest.mitmas
ON vhcono = mmcono
AND vhitno = mmitno
where uwcono = 1
and uwstdt >= ?
and uwlvdt <= ?
and uwcuno = ''JBHE0001''
and uwagst = ''20''
and (vhitno LIKE ''%'' || ? || ''%''
or mmitds LIKE ''%'' || ? || ''%'')',
@From, @To, @Search, @Search) at M3_TEST_ODBC
However, DB2 is case sensitive - how do I make the two LIKES on mmitds and vhitno case insensitive?
This is a FAQ so maybe you should read more, for example: this article is one of many, and various approaches exist. The sample principles apply for i-series as Linux/Unix/Windows even if the implementations vary.
If you lack access to make table-changes (e.g. to add columns, indexes etc) then you might suffer the performance penalties of using
UPPER()
orLOWER()
on the predicate columns. This may result in indexes on those columns being unable to be used and worse performance.You should first verify if the relevant columns in the Db2 tables really have mixed-case values, and if they only have a single case then alter your query to ensure you compare against that case.
If the columns have mixed-case values and no fixed-case column (or UDF) exists, and if your query will be frequently run for a vital business purpose, then best advice is to ensure the table has an appropriate design (to support case insensitive comparisons) via any of a number of methods.
If Regular expression functions are available in your version of Db2, you might also consider using REGEXP_LIKE and a suitable regular expression.
You could use something like this:
Beware: This could affect index selection, but you can create an index like this:
If you were using SQL embedded in RPG, you could set the program to use case insensitive sorts and comparisons with
To do this with JDBC, you need to set the following driver properties:
For an ODBC connection you need to have the following connection properties set:
Database setting
There is a database config setting you can set at database creation. It's based on unicode, though.
This worked for me. As you can see, ..._S2 ignores case, too.
Using a newer standard version, it should look like this:
Collation keywords:
UCA400R1
= Unicode Standard 4.0 = CLDR version 1.2UCA500R1
= Unicode Standard 5.0 = CLDR version 1.5.1CLDR181
= Unicode Standard 5.2 = CLDR version 1.8.1If your database is already created, there is supposed to be a way to change the setting.
I do have problems executing this, but for all I know it is supposed to work.
Generated table row
Other options are e.g. generating a upper case row: