Convert int to string problem


How do i convert an int to a string with prefix zeros.

For example convert the number 5 to the string '0000005'?
Who is Participating?
avalenzuelaConnect With a Mentor Commented:
You could do this
if you need a fixed lenght result

The example converts to a 10 chars leading zeros string..

select Replicate('0',10-len(55))  +  cast(55 as varchar(10))
Patrick MatthewsCommented:
SELECT MyInt, RIGHT('0000000' + CONVERT(varchar, MyInt), 7) AS LeadingZeroes
FROM SomeTable
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.