How to add leading zeros in sybase ase

max picture max · Mar 23, 2016 · Viewed 8.3k times · Source

Need to add leading zeros to column values(varchar) and update it in same table. ex: 431 as 000431, 5431 as 005431, 64531 as 064531, basically i need to substitute zeros to the data so that it is 6 digits. this is in sybase ase.

thanks

Answer

maf-soft picture maf-soft · Mar 30, 2017

If you can't use LPAD(), and the source number is an integer, this solution is maybe a little nicer than yours:

RIGHT(1000000+Number, 6)

But, as yours, it produces unexpected results if the value is negative or has more than 6 digits.