Select The correct datatype for a field in a table by
SELECT OPB_TARG.TARGET_NAME AS TABLE_NAME, OPB_TARG_FLD.FLDNO, OPB_TARG_FLD.TARGET_NAME AS FIELD_NAME, OPB_MMD_DATATYPE.DATATYPE_NAME
FROM
(select * from INFA.OPB_TARG s where exists (select max(i.version_number), src_id from INFA.OPB_TARG i where I.TARGET_ID = s.target_id group by target_id having S.VERSION_NUMBER = max(i.version_number))) OPB_TARG,
INFA.OPB_TARG_FLD,
(select * from OPB_MMD_DATATYPE o where exists (select min(ORDER_NUM) min_order_num ,NATIVE_DATATYPE, PM_DATATYPE, DBTYPE_ID FROM OPB_MMD_DATATYPE i where I.DBTYPE_ID=O.DBTYPE_ID and I.NATIVE_DATATYPE=O.NATIVE_DATATYPE and I.PM_DATATYPE = O.PM_DATATYPE group by NATIVE_DATATYPE, PM_DATATYPE, DBTYPE_ID having o.ORDER_NUM = min(ORDER_NUM))) OPB_MMD_DATATYPE
WHERE OPB_TARG.TARGET_ID = OPB_TARG_FLD.TARGET_ID
and OPB_TARG_FLD.version_number = OPB_TARG.version_number
AND OPB_TARG_FLD.NDTYPE = OPB_MMD_DATATYPE.NATIVE_DATATYPE
AND OPB_TARG_FLD.DTYPE = OPB_MMD_DATATYPE.PM_DATATYPE
AND OPB_MMD_DATATYPE.DBTYPE_ID = OPB_TARG.DBTYPE
AND IS_VISIBLE != 0
order by 1,2