Why am I getting a [SQL0802] Data conversion of data mapping error exception?
The only solution I could find was to write a script that checks for blank values in the column and then updates them to zero when they are found.
SQL0802 - Data Conversion or Data Mapping Error
If the problem is divide-by-zero, you simply need to prevent the division from happening when the denominator is zero. The easiest way would be to sum
the numerator and denominator separately, then divide after that happens:
sum (
DB1.Tb1.CUR_CASH_SALES+DB1.Tb1.CUR_CHARGE_SALES-
DB1.Tb1.CUR_CASH_COST+DB1.Tb1.CUR_CHARGE_COST
) /
sum (
DB1.Tb1.CUR_CASH_SALES+DB1.Tb1.CUR_CHARGE_SALES
) as "Gross Margin"
Then you would only get a divide-by-zero if the denominator is zero for the entire category you are grouping on.
If it is still a problem, you will need to do something else in addition. Depending on what you want, you could:
- Use your
where
clause to exclude groups with a zero denominator from your output. - Put a
case
statement around the entire calculation that checks if the denominator is zero before calculating. If it is zero, replace the calculation with whatever output makes sense (zero, null, etc.).
Why am I getting Data conversion or data mapping error. SQLCODE=-802 on a simple DB2 select statement?
There was invalid decimal data in the table. There were blanks instead of zeros. I moved zeros into those blanks and that fixed the problem
Related Topics
Cannot Select from Update Returning Clause in Postgres
Is There a Severe Performance Hit for Using Foreign Keys in SQL Server
Ruby on Rails - Search in Database Based on a Query
How to Compare Software Versions Using SQL Server
Connecting to Oracle Database Using SQL Server Integration Services
How to Use Parameters with Rpostgresql (To Insert Data)
How to Add a Subtotal Row in SQL
Set Limit for a Table Rows in SQL
Writing Unicode from R to SQL Server
Manipulation of Large Files in R
How to Generate Date Series to Occupy Absent Dates in Google Biqquery
Rodbc SQLsave Table Creation Problems
Exporting a Clob to a Text File Using Oracle SQL Developer
Using an Alias Column in the Where Clause in Ms-SQL 2000
Rodbc Loses Time Values of Datetime When Result Set Is Large