SQL0802: Data conversion or data mapping error.

Problem : SQL0802: Data conversion or data mapping error.

Hi, I’m new to AS/400 and DB2 (we’re currently at ver 4.5)

I’ve got a C# application that uses an ODBC connection to retrieve data from a DB2 database.   When running the application I get the following error:  [OdbcException: ERROR [HY000] [IBM][Client Access Express ODBC Driver (32-bit)][DB2/400 SQL]SQL0802 – Data conversion or data mapping error.]

I was able to identify the record that’s causing the exception.  It looks like the following sql statement

SELECT * FROM CXLIB.TABLE WHERE CAST(SUBSTR(LTRIM(CXLIB.TABLE.FIELD), 2, LENGTH(CXLIB.TABLE.FIELD)) AS INTEGER) > 40

which is trying to filter by dollar amounts is failing when encountering the first dollar amount that contains a comma.  I’ve tried to determine the source data type, but when I run a File Field Description Listing from WRKDBF on the AS/400, the field type for this field is simply described as ‘A’, which I’m told stands for Alphanumeric(?) but I can’t seem to find any reference to such a type in the DB2 SQL reference I obtained online.  I’ve tried removing the comma with a REPLACE function, but apparently our version doesn’t support this built-in function.

Any suggestions on how to work around this problem?

Thanks in advance…


Solution: SQL0802: Data conversion or data mapping error.

Wow.  That really IS an old version of DB2.

Ok.  This might get ugly.  Especially since I’m only guessing at functionality available at that level.

case when length(cxlib.table.field) <
CAST(
case when length(ltrim(xclib.table.field))
SUBSTR(LTRIM(CXLIB.TABLE.FIELD), 2, LENGTH(CXLIB.TABLE.FIELD))
when length(ltrim (xclib.table.field)) = 9 then
substr(ltrim(cxlib.table.field), 2, 1) || substr(ltrim(cxlib.table.field), 4, 6)
when length(ltrim (xclib.table.field)) = 10 then
substr(ltrim(cxlib.table.field), 2, 2) || substr(ltrim(cxlib.table.field), 5, 6)
when length(ltrim (xclib.table.field)) = 11 then
substr(ltrim(cxlib.table.field, 2, 3) || substr(ltrim(cxlib.table.field), 6, 6)
end
AS INTEGER)