Link to home
Start Free TrialLog in
Avatar of RavenTim
RavenTim

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of Barry Cunney
Barry Cunney
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Member_2_861731
Assuming your column name is myCol, this could work.

SELECT LEFT(myCol,6)+REVERSE(SUBSTRING(myCol,7,2))+RIGHT(myCol,4)
Avatar of RavenTim
RavenTim

ASKER

Thanks!