Neo302
Neo302

Reputation: 150

How to reverse values in a string in T-SQL

Using T-SQL, I'm trying to find the easiest way to make:

"abc.def.ghi/jkl" become "abc/def/ghi.jkl"?

Basically switch the . and /

Thank you

Upvotes: 4

Views: 509

Answers (2)

george9170
george9170

Reputation:

SELECT REVERSE(@myvar) AS Reversed, 
RIGHT(@myVar, CHARINDEX(‘ ‘, REVERSE(@myvar))) as Lastname;

took the answer from this guys blog. The first google result. You will need to modify it for your needs

link text

Upvotes: 0

SQLMenace
SQLMenace

Reputation: 134971

One way

select replace(replace(replace('abc.def.ghi/jkl','/','-'),'.','/'),'-','.')

you need to use an intermediate step, I chose the - symbol, choose something which won't exist in your string

Upvotes: 10

Related Questions