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
Solved

Insert hyphens in text string

Posted on 2008-10-08
7
795 Views
Last Modified: 2010-04-21
Good afternoon.  I have been doing alot of reading on this, but, I am having problems with the examples I have tried to use.  My dilemma is this..I have a field entitled [Customer ID] in TblAccounts.  There are 12 characters in each field, and I need to insert two hyphens, one after the third character, and one after the characters from the right.  In other words, I need this:
 009000000010
to look like this :009-0000000-10

Thank you for your time,
Nikki
0
Comment
Question by:Nikki28838
  • 3
  • 2
  • 2
7 Comments
 
LVL 22

Expert Comment

by:Flyster
ID: 22672957
You could try the format function:

Format([Customer ID],"000-0000000-00")

Flyster
0
 
LVL 26

Accepted Solution

by:
jerryb30 earned 125 total points
ID: 22672961
select left(customerID, 3) & "-" and mid(customerid, 4,7) & "-" & right(customerid,2) as newCustomerID from tblAccounts
If it is always the two right characters which need a hyphen before them.
0
 

Author Closing Comment

by:Nikki28838
ID: 31504412
Wonderful, thank you very much!
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 26

Expert Comment

by:jerryb30
ID: 22673022
I was going to comment that Flyster's solution was more elegant and you ought to ignore my post.
Please consider re-opening for changing score unless there is some reason you cannot make Flyster's solution work.
0
 
LVL 22

Expert Comment

by:Flyster
ID: 22673450
jerryb30,

Thanks for the nice comment. I don't think my work has ever been described as "elegant" before. I have no problem with the points assignment. One nice thing about EE...... there's always another post to respond to! Thanks again.
0
 

Author Comment

by:Nikki28838
ID: 22673512
Hello.  Flysters did work...I just happened to use the other method first because I was in a hurry.  I apologize and will gladly move the points...if someone could tell me how?  Again, so sorry.
0
 
LVL 26

Expert Comment

by:jerryb30
ID: 22673594
You can, if desired, post a request in community support (with a link to this question), asking that it be re-opened for scoring.
Two ways of doing the same thing, but if I had seen Flyster's response before I posted miine (we were within seconds of each other), I would not have posted.  No need to apologize.  I just wanted to be fair to Flyster.
 
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

856 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