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

MS SQL 2005 substring - replace question

I have a field in a table that contains data that I need to manipulate for sorting.  And I need to do this just as an output  using a select query (I don't want to change it in the table).  I need to select 3 fields; tempid, type, location.    The "location" field contains the data to be manipulated.   Here's a few examples:

SB-01-F3-015 -  I need this to OUTPUT as SB-01-3F-015
SB-01-B4-010 -  I need this to OUTPUT as SB-01-4B-010
SB-01-D2-008 -  I need this to OUTPUT as SB-01-2D-008

I assume you use some kind of replace command...  The command will always be transposing the 4th and 5th character of the location field.
0
RavenTim
Asked:
RavenTim
1 Solution
 
Barry CunneyCommented:
SELECT LEFT(Location,6) + REVERSE(SUBSTRING(Location,7,2)) + RIGHT(Location,4)
FROM yourtable
0
 
LIONKINGCommented:
Assuming your column name is myCol, this could work.

SELECT LEFT(myCol,6)+REVERSE(SUBSTRING(myCol,7,2))+RIGHT(myCol,4)
0
 
RavenTimAuthor Commented:
Thanks!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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