I think I put the condition wrong. When udf_isnumeric() returns 1, does it mean the data is numeric or non-numeric. The code is assuming that return code ZERO represents the NUMERIC content.
In this condition 'WHEN I_PDT_GL IN('362114','362154') THEN.... ', you are checking whether the data is string or not. In case it is then you are trimming last two characters from it. Does this ensure that the remaining content is NUMERIC. Becasue you are casting it directly into DECIMAL after trimming last two characters, so it has to be numeric otherwise you get the same error.
Try the below code and see if it works out.
SELECT I_SYS_CLM
,D_EFF_RCD
,C_CLM
,C_STA_CLM
,C_TYP_SYS_IDV
,I_SYS_IDV
,C_POL
,C_AMS_CLM
, I_PDT_GL, C_PLN_QLF
,CASE WHEN I_PDT_GL IN('12984','22984') THEN
CASE WHEN UDF_ISNUMERIC(CLM.C_POL) = 0 THEN TRIM(CAST(CAST(CLM.C_POL AS DECIMAL (10,0) FORMAT '9999999999') AS CHAR(10)))
ELSE 'BAD DATA'
END
WHEN I_PDT_GL NOT IN('362114','362154') AND I_PDT_GL NOT IN('364154','364114')/*ADEPT*/ THEN
CLM.C_POL
WHEN I_PDT_GL IN('362114','362154') THEN/* MERLIN*/
CAST(CAST(CASE WHEN SUBSTR(CLM.C_POL,1,1) = 'L' THEN
'00000000'
WHEN UDF_ISNUMERIC(CLM.C_POL) = 1 THEN
SUBSTRING(CLM.C_POL FROM 1 FOR CHAR_LENGTH(TRIM(CLM.C_POL))-2)
ELSE CLM.C_POL
END AS DECIMAL (8,0) FORMAT '99999999') AS CHAR(8))
WHEN I_PDT_GL IN('364154','364114')/*ADEPT*/ AND UDF_ISNUMERIC(CLM.C_POL) = 0 THEN
CAST(CAST(CLM.C_POL AS DECIMAL (8,0) FORMAT '99999999') AS CHAR(8))
ELSE CLM.C_POL
END AS "PRODUCT_NAME"
FROM PEARL_P.TLTC900_CLM CLM
↧
Case statement returning "Bad character in format or data...." - response (7) by Qaisar Aftab Kiani
↧