• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 669
  • 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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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