views:

64

answers:

2

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

+10  A: 

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

SQLMenace
+1, anyway he should replace '-' with a character that will never be in his input, in the case this is some general thing.
Adrian Faciu
Nice. The intermediate step FTW! :)
Neo302
A: 

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

george9170
No, the OP didn't mean "reverse", he meant "exchange". (but your reversing undoubtedly works)
Hans Kesting