[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Convert int to string problem

Posted on 2010-09-06
2
Medium Priority
?
446 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

649 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