tags:

views:

49

answers:

2

I'm having great difficultly making my DB2 (AS/400) queries case insensitive.

For example:

SELECT *
FROM NameTable
WHERE LastName = 'smith'

Will return no results, but the following returns 1000's of results:

SELECT *
FROM NameTable
WHERE LastName = 'Smith'

I've read of putting SortSequence/SortType into your connection string but have had no luck... anyone have exepierence with this?

Edit:

Here's the stored procedure:

BEGIN
DECLARE CR CURSOR FOR
SELECT  T . ID ,
    T . LASTNAME ,
    T . FIRSTNAME ,
    T . MIDDLENAME ,
    T . STREETNAME || ' ' || T . ADDRESS2 || ' ' || T . CITY || ' ' || T . STATE || ' ' || T . ZIPCODE AS ADDRESS ,
    T . GENDER ,
    T . DOB ,
    T . SSN ,
    T . OTHERINFO ,
    T . APPLICATION
FROM
    ( SELECT R . * , ROW_NUMBER ( ) OVER ( ) AS ROW_NUM
    FROM CPSAB32.VW_MYVIEW
    WHERE R . LASTNAME = IFNULL ( @LASTNAME , LASTNAME )
    AND R . FIRSTNAME = IFNULL ( @FIRSTNAME , FIRSTNAME )
    AND R . MIDDLENAME = IFNULL ( @MIDDLENAME , MIDDLENAME )
    AND R . DOB = IFNULL ( @DOB , DOB )
    AND R . STREETNAME = IFNULL ( @STREETNAME , STREETNAME )
    AND R . CITY = IFNULL ( @CITY , CITY )
    AND R . STATE = IFNULL ( @STATE , STATE )
    AND R . ZIPCODE = IFNULL ( @ZIPCODE , ZIPCODE )
    AND R . SSN = IFNULL ( @SSN , SSN )
    FETCH FIRST 500 ROWS ONLY )
AS T
WHERE ROW_NUM <= @MAXRECORDS
OPTIMIZE FOR 500 ROW ;

OPEN CR ;
RETURN ;
+2  A: 

Why not do this:

WHERE lower(LastName) = 'smith'

If you're worried about performance (i.e. the query not using an index), keep in mind that DB2 has function indexes, which you can read about here. So essentially, you can create an index on upper(LastName).

EDIT To do the debugging technique I discussed in the comments, you could do something like this:

create table log (msg varchar(100, dt date);

Then in your SP, you can insert messages to this table for debugging purposes:

insert into log (msg, dt) select 'inside the SP', current_date from sysibm.sysdummy1;

Then after the SP runs, you can select from this log table to see what happened.

dcp
@dcp I've tried that before but it typically returns this message ERROR [HY000] [IBM][iSeries Access ODBC Driver][DB2 UDB]SQL0255 - Function not supported for query.
mint
@mint - Hmm, lower seems to be a pretty standard DB2 function, I remember using it as far back as the late 1990's. Here's a reference: http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc.sqlref/db2z_bif_lower.htm If your DB doesn't support lower/upper, it must be very old indeed.
dcp
@dcp Well, I can run the straight sql of it fine. But in my application I call a stored procedure and then it seems to flop... no idea why!
mint
@mint - Tip: one technique I use to debug stored procedures is to create a temp table and insert messages to it. Then you can see what's going on. This is useful if you don't have the ability to step through the code in some debugger (I'm not sure what tools you have).
dcp
@mint - can you post your SP?
Leslie
@mint - See my latest edit for an example of the debugging technique I described.
dcp
A: 

I did something similar when I wanted a case insensitive search. I used UPPER(mtfield) = 'SEARCHSTRING'. I know this works.

Mike Wills