Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Insert hyphens in text string

Posted on 2008-10-08
7
Medium Priority
?
827 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 500 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
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.

 
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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
If you’re using QODBC to update QuickBooks data from Microsoft® Access but Access is not showing the updated data, you could have set up QODBC incorrectly.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

876 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