max
max

Reputation: 59

How to add leading zeros in sybase ase

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

Upvotes: 4

Views: 12847

Answers (2)

maf-soft
maf-soft

Reputation: 2552

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.

Upvotes: 3

RobV
RobV

Reputation: 2378

In case you're running ASE 16.0SP01 or later, you can use the built-in function LPAD(). Otherwise, the expression you quoted is the way to go (which you could wrap into a SQL function to make it easier to use)

Upvotes: 1

Related Questions