• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 676
  • Last Modified:

INSERT DASHES INTO A STRING

i NEED TO INSERT DASHES INTO A STRING OF 11 CHARACTERS XXXXX-XXXX-XX in SQL Server 2005
I can extract the left 5 and concatenate the dash, using Left(column name,5) and the same thing for the last two positions with Right, but how do I obtain the middle four?  I didn't see a mid function as there is in Access.  
Thanks for your assistance
0
LenTompkins
Asked:
LenTompkins
2 Solutions
 
UnifiedISCommented:
Use Substring

SUBSTRING ( expression , start , length )
0
 
matthewrhoadesCommented:
Since these are fixed length strings, you can use the SUBSTRING function

update table
set column = substring(column, 1, 5)  + '-' + substring(column, 5, 4) + '-' + substring(column, 9, 2)

You will have to fudge the numbers a little bit, but that is the gist of it.

Try it with select before you do an actual update.
0
 
LenTompkinsAuthor Commented:
I split the points because you both wrote your answers at about the same time.  That worked great.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now