Solved

Character manipulation in sql query

Posted on 2011-09-18
4
330 Views
Last Modified: 2012-05-12
I don't know if this can be done or not.
I have a field in a query that always starts with a letter, and is followed by 1 to 7 numbers.  I need to insert 0's after the letter so the result is 7 characters long.

Examples:
D123  --> D000123
E01 --> E000001
0
Comment
Question by:rrhandle8
  • 3
4 Comments
 
LVL 75
ID: 36557157
Example:

Left("D123",1) & Format(Mid("D123",2),"0000000")

returns
D0000123

mx
0
 
LVL 75
ID: 36557160
Update query:

UPDATE Table1 SET Table1.FIELD1 = Left([FIELD1],1) & Format(Mid([FIELD1],2),"0000000");


mx
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 500 total points
ID: 36557170
OOPS ... 7 total


Left("D123",1) & Format(Mid("D123",2),"000000")

UPDATE Table1 SET Table1.FIELD1 = Left([FIELD1],1) & Format(Mid([FIELD1],2),"000000");
0
 

Author Comment

by:rrhandle8
ID: 36557194
Perfect!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now