lundi 21 mars 2016

DB2 IF and LENGTH usage

I have this DB2 table

A      |  B      | C

aaaa   |123      |
bbbb   |1        |
cccc   |123456   |

All columns are varchars. I would like to have the column C filled up with the contents of B concatenated with the contents of A. BUT the max length of C is 8. So if the concatenated string exceeds 8, then i would like to have only 5 characters + "...".

Basically:

if(length(A) + length(B) > maximum(C) {
      //display only the first (maximum(C) - 3) characters, then add "..."
} else {
     // display B + A
}

How can i do this in DB2?

Aucun commentaire:

Enregistrer un commentaire