?
Solved

Convert int to string problem

Posted on 2010-09-06
2
Medium Priority
?
451 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 93

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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

839 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