?
Solved

Add characters to sql server field

Posted on 2004-11-23
2
Medium Priority
?
260 Views
Last Modified: 2006-11-17
I have a field in sql server that is 6 characters long but the data can range from 1 - 6 characters in length.  I want to add '0' to the field where the length is less than 6. Say if the field contains 2003 I want to replace it with 002003 same goes for 52 I want to replace it with 000052.  Any ideas would be greatly appreciated.

Thanks
Tim
0
Comment
Question by:tbailey922
2 Comments
 
LVL 16

Accepted Solution

by:
muzzy2003 earned 1000 total points
ID: 12655467
UPDATE Table
SET Field = RIGHT('000000' + RTRIM(LTRIM(Field)), 6)
0
 

Author Comment

by:tbailey922
ID: 12655544
Excellent!!

Thanks
0

Featured Post

Technology Partners: 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

When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

850 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