text parsing - Remove trailing zeros after decimal point in DB2 -
i have following values in label table in db2 (version : 9.5.8)
select field4 label ur
1.5000 0.006 9.0001 104.2500 17.0000 3.5000
is possible eliminate trailing zeros after decimal point update query in db2?
if digits zeros after decimal point, need keep .0
, however.
expected output:
1.5 0.006 9.0001 104.25 17.0 3.5
you should consider changing column kind of numeric. anyhow, heres idea:
with t(s) ( values '1.5000', '0.006', '9.0001','104.2500','17.0000','3.5' ) select translate(rtrim(translate(s,' ','0')),'0',' ') || case when translate(rtrim(translate(s,' ','0')),'0',' ') '%.' '0' else '' end t
1.5
0.006
9.0001
104.25
17.0
3.5
using cte translate(rtrim(translate(s,' ','0')),'0',' ') minimize number of function calls.
with t(s) (values '1.5000', '0.006', '9.0001','104.2500','17.0000','3.5') , u(s) ( select translate(rtrim(translate(s,' ','0')),'0',' ') t ) select s || case when s '%.' '0' else '' end u
1.5
0.006
9.0001
104.25
17.0
3.5
Comments
Post a Comment