Link to home
Start Free TrialLog in
Avatar of Zolf
ZolfFlag for United Arab Emirates

asked on

Add leading zero when number is less than 10?


Hi there,

My database is MySQL and I have a sql query which returns the month and I want to add 0 before the single digit month.

select distinct monthname,onthNumberOfYearfrom datedimension p 
where datekey >= 13990101

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Yes, you could do it with two function calls.  I can probably come up with a way to use even more than two.

Normally you do it with one:  LPAD.

https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_lpad

lpad(MonthNumberOfYearfrom ,2,'0')