Skip to content
Advertisement

Having weird exception using MAX(CASE WHEN) in query: DB2.iSeries.iDB2DCFunctionErrorException: ‘An unexpected exception occurred

I have the following query to put some data from rows in columns:

But when I try to run it in the following code:

I get this exception:

“IBM.Data.DB2.iSeries.iDB2DCFunctionErrorException: ‘An unexpected exception occurred. Type: System.AccessViolationException, Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt..'”

I have other queries that work just fine, but this one does not. I even tried the query on SQL as follows (credit to Gordon Linoff for providing this code):

And it works. What can I do?

Drivers:

Client Access ODBC Driver (32-bit) 12.00.00.00

iSeries Access ODBC Driver 12.00.00.00

EDIT: Here’s the sql query without being a string.

Advertisement

Answer

OK, so I finally found out what was the problem. For some reason, I’m not able to CAST to float inside the MAX. If I remove both CAST from the query, the exception is gone and everything works. I’m not sure why this happens, and if anyone could explain that, it would be very helpful as I need to cast those values to float. Also, if I SELECT more columns, it is necessary to add said columns into the GROUP BY statement. Anyways, here’s the modified code that works:

EDIT: Found out the way to cast them. It turns out I was getting some nulls, some blank fields, and I was trying to assign a number to a string. This is the code now:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement