Solved

Convert int to string problem

Posted on 2010-09-06
2
417 Views
Last Modified: 2013-11-05
Hi,

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

For example convert the number 5 to the string '0000005'?
0
Comment
Question by:cossy74
2 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 33614178
SELECT MyInt, RIGHT('0000000' + CONVERT(varchar, MyInt), 7) AS LeadingZeroes
FROM SomeTable
0
 
LVL 3

Accepted Solution

by:
avalenzuela earned 500 total points
ID: 33614309
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))
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question