Solved

Format select statement to pad text with leading zeros

Posted on 2010-11-23
6
687 Views
Last Modified: 2012-05-10
Hello,

What is the code used to format a field selected so that it always has a fixed number of characters (i.e., padded with leading 0s for a total length of 10)?

Example for Field1:

Actual                   Desired
123                        0000000123

Thanks,
SASnewbie
0
Comment
Question by:SASnewbie
[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
  • 3
  • 3
6 Comments
 
LVL 13

Expert Comment

by:Philip Pinnell
ID: 34197302
something like

select RIGHT ('0000000000'+field,10 ) from table
0
 

Author Comment

by:SASnewbie
ID: 34197304
Here is a sample of my select statement that I have tried:

SELECT    Client, right(concat("0000000000", Field1),10) as Loan_num,  Result
0
 
LVL 13

Accepted Solution

by:
Philip Pinnell earned 250 total points
ID: 34197351
concat is MySQL not MS sql

select RIGHT ('0000000000'+field1,10 ) from table
0
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.

 

Author Comment

by:SASnewbie
ID: 34197373
Hi andycrofts,

I'll try that and get right back to you,

Thanks!
0
 

Author Comment

by:SASnewbie
ID: 34197518
Thanks! That works perfectly!
0
 
LVL 13

Expert Comment

by:Philip Pinnell
ID: 34197535
Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

734 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