mysql - Pad Varchar with 0 in SQL Server 2005 -


i have tried following this , this need pad column zeros.

so have field

name_id 1 2 21 74 

and want like

name_id 001 002 021 074 

so have tried doing this:

select right('000'+ name_id,3) tblcoordinates; 

but result is:

right('000'+name_id,3) 1 2 21 74 

i using mysql server 2005. wrong select statement? thanks

you need convert name_id varchar first:

select right('000' + convert(varchar(3), name_id), 3) tblcoordinates; 

if you're using mysql, there built-in function lpad()

select lpad(name_id, 3, '0') tblcoordinates; 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -