Sunday 15 March 2015

Find the max integer value of string numbers in DB2 -


I have a table that has a special column filled with numeric values, but they are string. So 99 number is actually maintained as '99' How do I find the maximum value of this column? If I use the standard MAX () function, then select:

  Select the max (column) from the table  

Only the textual Get (I think) Max. Therefore, if '99' and '888' are in the column, then '99' has returned. Any easy way to get the maximum integer value back?

  select the maximum (int (column) table  

or pad as a string for column length (assuming length 10):

  Maximum (LPAD (column, 10, '0') from the table  

No comments:

Post a Comment