Reputation: 7906
I want to update a column in my table with concat of 2 fields. It works fine, but i want to append 0 to one of the field if its not 2 digits because i want my month data to be 2 digits long. What i have in months column is single digit data.
update employee_status set year_month = concat(year,month);
Upvotes: 1
Views: 210
Reputation: 40021
Sounds like you want lpad
update employee_status set year_month = concat(year, lpad(month, 2, '0'));
Upvotes: 2
Reputation: 2896
Try this :
update employee_status set year_month = concat(year, (if(length(month)) == 2, month, concat(0,month)));
Upvotes: 1
Reputation: 77896
Try this:
update employee_status set year_month = concat(year, lpad(month,2,'0'));
Upvotes: 2