Search code examples
sqldb2casevarchar

DB2 varchar characters casE?


firstly sorry for the ambiguous title I couldn't think of a proper title, but anyway I have a column titled unit_id it is a varchar. and some of the data comes in with 3 characters, but i need them to have a 0 in front of the values. I was thinking of doing a case or if but im not sure how to write it. RECAP data comes in as 164, but I would like it to come in as 0164 thanks in advance guys!


Solution

  • It sounds like you're looking for the LPAD function:

    SELECT LPAD(unit_id,4,'0') FROM your_table